|
- #include <algorithm>
- #include <iostream>
- #include <cmath>
- #include <cstring>
- #include <map>
- #include <string>
- #include <vector>
- #include <queue>
- #include <stack>
- #include <cstdio>
- #include <cstdlib>
- using namespace std;
- int n,m,l=0,fa[201000],x,y,a,all=0;
- int getf(int u)
- {
- if(u==fa[u]) return u;
- int f=getf(fa[u]);
- fa[u]=f;
- return f;
- }
- void he(int x,int y)
- {
- int t1=getf(x),t2=getf(y);
- if(t1!=t2)
- fa[t1]=t2;
- }
- int main()
- {
- scanf("%d%d",&n,&m);
- for(int i=1;i<=3*n;i++)
- fa[i]=i;
- while(m--)
- {
- scanf("%d%d%d",&a,&x,&y);
- if(x>n||y>n)
- {
- all++;
- continue;
- }
- if(a==1)
- {
- if(getf(x)==getf(y+n)||getf(x)==getf(y+n+n))
- {
- all++;
- continue;
- }
- he(x,y);he(x+n,y+n);he(x+n+n,y+n+n);
- }
- else
- {
- if(x==y||getf(x)==getf(y)||getf(x)==getf(y+n))
- {
- all++;
- continue;
- }
- he(x+n,y);he(x,y+n+n);he(y+n,x+n+n);
- }
- }
- printf("%d",all);
- return 0;
- }
复制代码 |
|