Food Chain


Submit solution

Points: 1
Time limit: 2.0s
Memory limit: 256M

Problem type
Allowed languages
Python

Problem Description

In the animal kingdom, there are three types of animals: A, B, and C. The food chain among them forms an interesting cycle:

  • A eats B,
  • B eats C,
  • C eats A.

There are N animals, numbered 1 to N.
Each animal is one of A, B, or C, but we do not know which one.

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

  1. 1 X Y — meaning X and Y are the same type.
  2. 2 X Y — meaning X eats Y.

This person says K statements one after another. Some are true, some are false.

A statement is false if it satisfies any of the following:

  1. It conflicts with some previous true statements.
  2. X or Y is greater than N.
  3. It says X eats X.

Your task is to determine the total number of false statements, given N and the K statements.

Input Format
The first line contains two integers N and K, separated by a space.
The next K lines each contain three integers D, X, Y, separated by spaces, where D indicates the type of statement.

Output Format
A single integer, the number of false statements.

Data Range
1 ≤ N ≤ 50000
0 ≤ K ≤ 100000

Input Sample:

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

Output Sample:

3

Comments

There are no comments at the moment.