杭电hdu 3038 how many answers are wrong 并查集求解
来源:互联网 发布:ipad建筑绘图软件 编辑:程序博客网 时间:2024/05/16 04:04
http://acm.hdu.edu.cn/showproblem.php?pid=3038
经过网上的搜罗,基本上明白了这个题的意思,网站http://hi.baidu.com/fp_lv/blog/item/a471530a86df7b90d53f7c2c.html讲解的很清楚,我这里只记录下网址和我的代码,以便以后随时查看。
#include <stdio.h>#define MAX 200001int father[MAX];int sum[MAX];//存储从1到i相加的结果int n,m;int ai, bi, si;void init(){for(int i = 0; i <= n; i ++){father[i] = i;sum[i] = 0;}}int getfather(int x){if(x == father[x])return x;int now = getfather(father[x]);//sum[x] += sum[father[x]];//需要我研究的地方father[x] = now;return now;}bool join(int a, int b){int fa = getfather(a);int fb = getfather(b);if(fa == fb)return false;father[fb] = fa;sum[fb] = sum[a] - sum[b] + si;//return true;}int main(){//freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout);while(~scanf("%d%d",&n,&m)){init();int ans = 0;while(m--){scanf("%d%d%d",&ai, &bi, &si);ai --;if(!join(ai, bi)&&sum[bi] - sum[ai] != si)ans ++;}printf("%d\n", ans);}return 0;}
- 杭电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
- [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 并查集
- 杭电3038 How Many Answers Are Wrong(带权并查集-经典)
- hdoj 3038How Many Answers Are Wrong 并查集
- HDOJ 3038 How Many Answers Are Wrong 并查集
- HDU 3038 How Many Answers Are Wrong (并查集好题)(带权并查集)
- 【杭电oj】3038 - How Many Answers Are Wrong(带权并查集,好题)
- HDU 3038 How Many Answers Are Wrong? (带权并查集)
- HDU 2082 找单词(母函数)
- 项目感想(存储过程)
- Android中string.xml中的替换
- Microsoft与Websense合作强化资料保护并扩充DLP方案
- android ImageView android:scaleType属性详解
- 杭电hdu 3038 how many answers are wrong 并查集求解
- Tomcat 使用Log4j问题
- 统计Linux kernel的启动时间
- j_link调试K60
- cocos2d-x demo资源
- 12-3-23关于一级指针,二级指针
- OpenCV学习:cvPyrSegmentation金字塔分割算法
- qt下的跨目录多工程编译
- 移动指定窗口位置