HDU 3038 How Many Answers Are Wrong
2011-06-27 14:34
225 查看
http://acm.hdu.edu.cn/showproblem.php?pid=3038
#include<iostream> using namespace std; #define N 200001 int a,b,k; struct node{ int father; int len; }p ; void init(int n){ for(int i=0;i<=n;i++){ p[i].father=i; p[i].len=0; } } int find(int x){ if(x==p[x].father) return p[x].father; int r=find(p[x].father); p[x].len+=p[p[x].father].len; return p[x].father=r; } bool merge(int x,int y){ int fx=find(x); int fy=find(y); if(fx==fy) return p[y].len-p[x].len!=k; p[fy].father=fx; p[fy].len=p[x].len-p[y].len+k; return false; } int main(void){ int n,m; while(~scanf("%d%d",&n,&m)){ int c=0; init(n); while(m--){ scanf("%d%d%d",&a,&b,&k); a--; if(merge(a,b)) c++; } printf("%d/n",c); } }
相关文章推荐
- hdu 3038 How Many Answers Are Wrong
- HDU-3038 How Many Answers Are Wrong 并查集
- hdu 3038 How Many Answers Are Wrong (带权并查集)
- hdu 3038 How Many Answers Are Wrong(带权并查集)
- HDU 3038 How Many Answers Are Wrong【带权并查集】
- hdu 3038 How Many Answers Are Wrong (带权并查集)
- HDU 3038 How Many Answers Are Wrong 【神奇并查集】
- hdu 3038 How Many Answers Are Wrong
- hdu 3038 How Many Answers Are Wrong(带权并查集)
- How Many Answers Are Wrong HDU - 3038 (并查集)题解
- How Many Answers Are Wrong HDU - 3038 (带权并查集)
- hdu 3038 How Many Answers Are Wrong
- 并查集-HDU-3038-How Many Answers Are Wrong
- HDU-3038-How Many Answers Are Wrong [带权并查集]
- HDU-3038 How Many Answers Are Wrong
- hdu 3038 How Many Answers Are Wrong(并查集变种)
- hdu 3038 How Many Answers Are Wrong
- HDU 3038 - How Many Answers Are Wrong
- hdu 3038D - How Many Answers Are Wrong [kuangbin带你飞]专题五 并查集
- hdu 3038 How Many Answers Are Wrong(带权并查集)