Count records that are invalid or contradict earlier records, treating same-kind and eats relations consistently.
Medium7Union-findGraphNo attempts yetTime limit2sMemory limit512 MBN animals live on planet Zeta. Minho numbered them 1, 2, ..., N to tell them apart. Every animal on the planet is one of three kinds, A, B, or C, and A eats B, B eats C, and C eats A.
Minho watched the planet for a long time and now wants to draw an ecology map from the records he kept. Each record is one of two kinds.
Minho reads the records in order, from record 1 to record K, and fills in the map as he goes. Some records name an x or a y that is not an animal number, and some records contradict the part of the map he has already filled in. When Minho meets such a record he skips it and does not put it on the map. A skipped record has no effect on how the following records are judged.
Write a program that counts the records Minho has to skip.
The first line contains N and K separated by a space (1≤N≤50,000, 0≤K≤100,000). N is the number of animals and K is the number of records Minho kept.
Each of the next K lines holds one record as three integers ti, xi, yi. ti is 1 or 2, and xi and yi are 32-bit signed integers.
Print the number of bad records Minho has to skip.