Take the right and check the set of silly questions
Use the split method to grass over.
Split code:
# include <stdio.h># include <string.h>int set[150005], N, K, d;int find (int x) {int S, temp;for (s=x; SET[S]&G t;=0; S=set[s]); while (s! = x) {temp = set[x];set[x] = S;x = temp;} return s;} void Union_set (int x, int y) {x = find (x); y = find (y); int temp = set[x] + set[y];if (x! = y) {if (set[x] > Set[y]) {Set [x] = y;set[y] = temp;} else {Set[y] = x;set[x] = temp;}}} int main (void) {int x, Y, cnt=0;scanf ("%d%d", &n,&k), memset (set,-1,sizeof (set)), while (k--) {scanf ("%d%d%d", &d,&x,&y); if (X>n | | y>n) {cnt++;continue;} if (d = = 1) {if (find (x) = = Find (y+n) | | find (x) = = Find (y+2*n)) {cnt++;} else {union_set (x, y); Union_set (x+n,y+n); Union_set (x+2*n,y+2*n);}} else {if (find (x) = = Find (y) | | find (x) = = Find (y+2*n)) Cnt++;else {union_set (x,y+n); Union_set (x+n,y+n*2); Union_set (x+n* 2,y);}}} printf ("%d\n", CNT); return 0;}
2016 Summer Camp Training 2 C problem food chain