标签:conflict lease modern die nts you ica input ini
Description
Input
Output
Sample Input
Sample Output
Hint
Hint: (PS: the 5th and 10th requests are incorrect)
一个类似的题:
https://www.cnblogs.com/yinbiao/p/9460772.html
code:
#include<queue> #include<set> #include<cstdio> #include <iostream> #include<algorithm> #include<cstring> #include<cmath> #include<map> #include<string> #include<string.h> #include<memory> using namespace std; #define max_v 50005 #define INF 9999999 int pa[max_v]; int sum[max_v]; int n,m; int ans; void init() { for(int i=0;i<=n;i++) { pa[i]=i; sum[i]=0; } } int find_set(int x) { if(pa[x]!=x) { int t=pa[x]; pa[x]=find_set(pa[x]); sum[x]+=sum[t];//!!! } return pa[x]; } void union_set(int a,int b,int v) { int x=find_set(a); int y=find_set(b); if(x==y) { if(sum[a]-sum[b]!=v)//!!! ans++; }else { pa[x]=y; sum[x]=sum[b]-sum[a]+v;//!!! } } int main() { while(~scanf("%d %d",&n,&m)) { int x,y,w; ans=0; init(); for(int i=0;i<m;i++) { scanf("%d %d %d",&x,&y,&w); union_set(x,y,w); } printf("%d\n",ans); } return 0; }
HDU 3047 Zjnu Stadium(带权并查集,难想到)
标签:conflict lease modern die nts you ica input ini
原文地址:https://www.cnblogs.com/yinbiao/p/9460838.html