看!题面被吃掉了!
http://codevs.cn/problem/1074/
带权并查集。。。。
注意关系
#include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=50005;
int n,m,u,v,t,ans,aa,bb;
struct cyq
{
int fa,s;
}f[N];
int find(int x){
if(f[x].fa!=x){
int tmp=find(f[x].fa);
f[x].s=(f[x].s+f[f[x].fa].s)%3;
f[x].fa=tmp;
}
return f[x].fa;
}
inline int get(){
char cc=getchar();
int res=0;
while (cc<'0'||cc>'9') cc=getchar();
while (cc>='0'&&cc<='9'){
res=(res<<3)+(res<<1)+cc-'0';
cc=getchar();
}
return res;
}
void check()
{
if(u>n || v>n || t==2&&u==v) {ans++;return;}
aa=find(u),bb=find(v);
if(f[aa].fa==f[bb].fa){
if(f[u].s!=f[v].s&&t==1) {ans++;return;}
if((f[v].s-f[u].s+3)%3!=1 && t==2) {ans++;return;}
}
f[bb].fa=aa;
f[bb].s=(f[u].s-f[v].s+t+2)%3;
}
int main()
{
n=get();m=get();
for(int i=1;i<=n;i++) {f[i].fa=i;f[i].s=1;}
for(int i=1;i<=m;i++) {
t=get();u=get();v=get();
check();
}
printf("%d\n",ans);
return 0;
}