标签:lse res cst += cin str || print class
#include<iostream> #include<cstdio> using namespace std; const int N=100010; int p[N]; int d[N]; int find(int x) { if(p[x]!=x) { int u=find(p[x]); d[x]+=d[p[x]]; p[x]=u; } return p[x]; } int main() { int n,k; int res=0; cin>>n>>k; for(int i=1;i<=n;i++) p[i]=i; while(k--) { int t,x,y; scanf("%d%d%d",&t,&x,&y); if(x>n||y>n) { res++; continue; } int fx=find(x); int fy=find(y); if(t==1) { if(fx==fy) { if((d[x]-d[y])%3) res++; } else { p[fx]=fy; d[fx]=d[y]-d[x]; } } else if (t==2) { if(fx==fy) { if((d[x]-d[y]-1)%3) res++; } else { p[fx]=fy; d[fx]=d[y]-d[x]+1; } } } printf("%d",res); return 0; }
标签:lse res cst += cin str || print class
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12248626.html