#P2024. Animal Food Chain
Animal Food Chain
Animal Food Chain
In the Animal Kingdom, there are three kinds of animals: A, B, and C. Their food chain forms an interesting cycle: (A) eats (B), (B) eats (C), and (C) eats (A). Given (N) animals numbered from 1 to (N), each animal is of one type (A, B, or C), but the exact type is unknown. We are provided with (K) statements that describe the relationships among these animals using two formats:
- 1 X Y: Indicates that animal \(X\) and animal \(Y\) are of the same type.
- 2 X Y: Indicates that animal \(X\) eats animal \(Y\).
- The statement contradicts any previously accepted (true) statements.
- Either \(X\) or \(Y\) is greater than \(N\).
- The statement suggests that an animal eats itself (i.e. \(X\) eats \(X\)).
inputFormat
The input begins with a line containing two integers (N) and (K) separated by a space. This is followed by (K) lines, each containing three integers. The first integer is either 1 or 2 representing the type of statement, and the next two integers (X) and (Y) correspond to the animal numbers involved in the statement.
outputFormat
Output a single integer representing the total number of false statements.
sample
100 7
1 101 1
2 1 2
2 2 3
2 3 3
1 1 3
2 3 1
1 5 5
3
</p>