EXAM | 프로그래밍의 벗 PivotOJ
PivotOJ

EXAM

시간 제한: 1000ms메모리 제한: 256MB출처: CHC 2012 Junior Croatian Olympiad in Informatics - Exam #2BOJ 3088
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

Martin is a beastly kid, who likes destroying his mother's flower pots. His mother owns N flower pots set up in a line and each pot has three integers written on it. When Martin crashes one of those pots, every pot right of that pot and shares at least on number with it also falls. Moreover, this rule is applied recursively, thus can result in crashing of whole lotta pots from just one direct pot crash from Martin. Beastly kids are known to be lazy and so is Martin, and he wants to know the minimal number of pots he has to crash directly so that all pots end up destroyed. 

[이미지 1]

On the picture above the second sample is shown. If Domagoj crashes pot 2, it will also crash pot 3 and pot 4 because of number 2 and additionaly pot 5 because of number 9 (found on pot 4). He needs to crash pot 1, which will cause the crashing of pot 3. This amounts to two direct crashes from Martin and is the solution to the sample. 

입력

First line contains one integer N (1 ≤ N ≤ 300 000). 

Each of the following N lines contains three integer Ai, Bi, Ci (1 ≤ Ai, Bi, Ci ≤ 1 000 000), three numbers written on the i-th pot from the left. 

출력

In the first and only line write the minimal number of pots Martin has to crash himself to crash all the pots. 

예제

예제 1

입력
3
1 2 3
2 3 4
4 5 6
출력
1

예제 2

입력
5
3 4 1
2 5 6
7 2 8
2 1 9
11 10 9
출력
2
코드를 제출하려면 로그인하세요.