标签:http targe get style org show col || https
https://www.luogu.org/problemnew/show/P2024
#include<cstdio> int f[50005]; int r[50005]; void init(int n){ for(int x=1; x<=n; x++){ f[x]=x; r[x]=0; } } int find(int x) { if(x==f[x]) return x; int t = f[x]; f[x]=find(f[x]); r[x]=(r[x]+r[t])%3; return f[x]; } void merge(int x, int y, int d){ int fx=find(x); int fy=find(y); f[fy]=fx; r[fy]=(r[x]-r[y]+3+(d-1))%3; } int main(){ int n, m; scanf("%d%d", &n, &m); init(n); int ans=0; int d, x, y; while(m--){ scanf("%d%d%d", &d, &x, &y); if(x>n || y>n || (d==2 && x==y)) ans++; else if(find(x)==find(y)) { if(d==1 && r[x]!=r[y]) ans++; if(d==2 && (r[x]+1)%3!=r[y]) ans++; } else merge(x, y, d); } printf("%d\n", ans); return 0; }
标签:http targe get style org show col || https
原文地址:https://www.cnblogs.com/Aze-qwq/p/9337824.html