int main(int argc , char *argv[]) { int n, k, x, y, z; int c = 0; int px, py, vx, vy; for (int i = 0 ; i < Max ; i++) fa[i] = i; memset(val, sizeof(val), 0); scanf("%d%d", &n, &k); for (int i = 1 ; i <= k ; i++) { scanf("%d%d%d", &z, &x, &y); if (x > n || y > n ) { c ++ ; continue ; } px = findroot(x); py = findroot(y); vx = val[x]; vy = val[y]; if (px == py) if (z == 1) if (vy == vx) continue; else c ++ ; else if ((vx - vy + N ) % N == 1) continue; else c ++ ; else if (z == 1) Union_set(y, x, 0); else Union_set(y, x, 1); } printf("%d\n", c); return 1; }
void Link(int x,int y) { Union_set(Find_set(x),Find_set(y)); return; }