- 食物链
- 2017-02-22 15:23:34 @
#include<iostream>
#include<sstream>
#include<ios>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<climits>
#include<cctype>
using namespace std;
int n,fa[50010],q,w,ans,cnt,k,temp,a[50010],key,x,y;
int find(int x)
{
if(fa[x]==x) return fa[x]=x;
int temp=fa[x];
fa[x]=find(fa[x]);
a[x]=(a[x]+a[temp])%3;
return fa[x];
}
void Union(int x,int y)
{
int fx,fy;
fx=find(x);fy=find(y);
if(fx!=fy) fa[fx]=fy;
}
int main()
{
for(int i=1;i<=30000;i++)
fa[i]=i;
scanf("%d%d",&n,&k);
for(int i=1;i<=k;i++)
{
scanf("%d%d%d",&key,&x,&y);
if(x>n||y>n) {ans++;continue;}
int dx=find(x),dy=find(y);
if(key==1)
{
if(dx!=dy) fa[dy]=dx,a[dy]=(a[x]-a[y]+3)%3;
else if(a[x]!=a[y]) ans++;
}
else
{
if(dx!=dy) fa[dy]=dx,a[dy]=(a[x]-a[y]+4)%3;
else if((a[x]+1)%3!=a[y]%3) ans++;
}
}
cout<<ans;
return 0;
}
1 条评论
-
sxb门徒 LV 6 @ 2017-02-22 15:44:50
我们正在讲这个题23333333
- 1