#P2024. [NOI2001] 食物链

[NOI2001] 食物链

Description

In the animal kingdom, there are three kinds of animals A,B,CA, B, C, and their food chain forms an interesting cycle. AA eats BB, BB eats CC, and CC eats AA.

There are NN animals, numbered from 11 to NN. Each animal is one of A,B,CA, B, C, but we do not know which.

Someone describes the food chain relationships among these NN animals using two kinds of statements:

  • Type 1: 1 X Y means XX and YY are of the same kind.
  • Type 2: 2 X Y means XX eats YY.

This person makes KK statements, one after another. Some are true and some are false. A statement is false if and only if it satisfies at least one of the following:

  • It contradicts some previous true statements.
  • XX or YY is greater than NN.
  • It claims that XX eats XX.

Your task is to output the total number of false statements.

Input Format

The first line contains two integers N,KN, K, indicating there are NN animals and KK statements.

Starting from the second line, each line contains one statement. The formats are as described in the problem statement and the samples.

Output Format

One line containing a single integer: the total number of false statements.

100 7
1 101 1
2 1 2
2 2 3
2 3 3
1 1 3
2 3 1
1 5 5

3

Hint

Constraints: For all testdata, 1N5×1041 \le N \le 5 \times 10^4, 1K1051 \le K \le 10^5.

Translated by ChatGPT 5