链接:
http://acm.hdu.edu.cn/showproblem.php?pid=3038
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/D
代码:
#include#include #include #include #include #include #include using namespace std;#define N 200005int n, m, f[N], r[N];int Find(int x){ int k=f[x]; if(x!=f[x]) { f[x]=Find(f[x]); r[x]=r[x]+r[k]; } return f[x];}int main(){ while(scanf("%d%d", &n, &m)!=EOF) { int ans=0, i, a, b, t, fa, fb; for(i=0; i<=n; i++) { f[i]=i; r[i]=0; } for(i=0; i