#include <bits/stdc++.h> #define dbg(x) std::cerr << #x << "=" << x << "\n" using i64 = long long; constexpr int N = 100005; int fa[N * 3]; int find(int x){ return fa[x] == x ? x : fa[x] = find(fa[x]); } void merge(int x,int y){ fa[find(x)] = find(y); } bool check(int x,int y){ return find(x) == find(y); } int main(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, k; std::cin >> n >> k; for(int i = 1; i <= 3 * n; i++){ fa[i] = i; } int ans = 0; while(k--){ int c,x,y; std::cin >> c >> x >> y; if(x > n || y > n){ ans++; continue; } if(c == 1){//检查是否是同类 if(check(x, y + n) || check(x + n, y)) ans++; //如果是敌对关系,那么假话+1 else{//否则合并三个集合内的朋友关系 merge(x, y); merge(x + n, y + n); merge(x + n + n, y + n + n); } }else{ if(check(x, y) || check(x, y + n)) ans++; //如果在一个族群或者发现是y吃x,那么假话+1 else{//否则记录下这一个真话 merge(x + n, y); merge(x + n + n, y + n); merge(x, y + n + n);//画图可得轮换对称性 } } } std::cout << ans; return 0; }