#t530. 食物链
食物链
Food Chain
Special for beginners, ^_^
Problem Description
In the animal kingdom there are three types of animals , and their food chain forms an interesting cycle: eats , eats , and eats .
There are animals numbered . Each animal is of one of the types , but we do not know which type each actually is.
Someone describes the food-chain relationships among these animals using two kinds of statements:
The first kind is 1 X Y, meaning and are of the same type.
The second kind is 2 X Y, meaning eats .
Regarding the animals, the person utters statements one after another in the two forms above; some of these statements are true and some are false. A statement is false (otherwise it is true) if any of the following three conditions holds:
- The current statement conflicts with some earlier true statement;
- In the current statement, or is greater than ;
- The current statement says that eats .
Your task is: given () and the statements (), output the total number of false statements.
Input Format
The first line contains two integers and separated by a space.
The next lines each contain three positive integers separated by spaces, where indicates the kind of statement.
If , then and are of the same type.
If , then eats .
Output Format
A single integer: the number of false statements.
Sample Input 1
100 7
1 101 1
2 1 2
2 2 3
2 3 3
1 1 3
2 3 1
1 5 5
Sample Output 1
3
Hint
$$\begin{matrix} 100&7\\\\1&101&1&false\\\\2&1&2&true\\\\2&2&3&true\\\\2&3&3&false\\\\1&1&3&false\\\\2&3&1&true\\\\1&5&5&true \end{matrix}$$Constraints
1s, 1024KiB for each test case.