hdu 3047(扩展并查集)
Zjnu Stadium
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2672 Accepted Submission(s): 1028
12th Zhejiang College Students Games 2007, there was a new stadium
built in Zhejiang Normal University. It was a modern stadium which
could hold thousands of people. The audience Seats made a circle. The
total number of columns were 300 numbered 1--300, counted clockwise, we
assume the number of rows were infinite.
These days, Busoniya want
to hold a large-scale theatrical performance in this stadium. There will
be N people go there numbered 1--N. Busoniya has Reserved several
seats. To make it funny, he makes M requests for these seats: A B X,
which means people numbered B must seat clockwise X distance from
people numbered A. For example: A is in column 4th and X is 2, then B
must in column 6th (6=4+2).
Now your task is to judge weather the
request is correct or not. The rule of your judgement is easy: when a
new request has conflicts against the foregoing ones then we define it
as incorrect, otherwise it is correct. Please find out all the
incorrect requests and count them as R.
For every case:
The first line has two integer N(1<=N<=50,000), M(0<=M<=100,000),separated by a space.
Then M lines follow, each line has 3 integer A(1<=A<=N), B(1<=B<=N), X(0<=X<300) (A!=B), separated by a space.
Output R, represents the number of incorrect request.
1 2 150
3 4 200
1 5 270
2 6 200
6 5 80
4 7 150
8 9 100
4 8 50
1 7 100
9 2 100
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
const int N =;
int father[N];
int sum[N]; ///记录当前结点到根结点的距离 int _find(int x){
if(x!=father[x]){
int t = father[x];
father[x] = _find(father[x]);
sum[x]+=sum[t];
}
return father[x];
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=;i<=n;i++){
father[i] = i;
sum[i] = ;
}
int ans = ;
while(m--){
int a,b,v;
scanf("%d%d%d",&a,&b,&v);
int roota = _find(a);
int rootb = _find(b);
if(roota==rootb){
if(sum[a]-sum[b]!=v) ans++;
}
else{
father[roota] = rootb;
sum[roota] = -sum[a]+sum[b]+v;
}
}
printf("%d\n",ans);
}
return ;
}
hdu 3047(扩展并查集)的更多相关文章
- hdu 3038(扩展并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 题意:给出区间[1,n],下面有m组数据,l r v区间[l,r]之和为v,每输入一组数据,判断 ...
- HDU 2818 (矢量并查集)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2818 题目大意:每次指定一块砖头,移动砖头所在堆到另一堆.查询指定砖头下面有几块砖头. 解题思路: ...
- hdu 1116 欧拉回路+并查集
http://acm.hdu.edu.cn/showproblem.php?pid=1116 给你一些英文单词,判断所有单词能不能连成一串,类似成语接龙的意思.但是如果有多个重复的单词时,也必须满足这 ...
- Bipartite Graph hdu 5313 bitset 并查集 二分图
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5313 题意: 给出n个顶点,m条边,问最多添加多少条边使之构成一个完全二分图 存储结构: bitset ...
- hdu 3081(二分+并查集+最大流||二分图匹配)
Marriage Match II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 2015 ACM/ICPC Asia Regional Changchun Online HDU - 5441 (离线+并查集)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5441 题意:给你n,m,k,代表n个城市,m条边,k次查询,每次查询输入一个x,然后让你一个城市对(u,v ...
- hdu 3536【并查集】
hdu 3536 题意: 有N个珠子,第i个珠子初始放在第i个城市.有两种操作: T A B:把A珠子所在城市的所有珠子放到B城市. Q A:输出A珠子所在城市编号,该城市有多少个珠子,该珠子转移了 ...
- HDU 1829 分组并查集
题意:有两种性别,每组数据表示是男女朋友,判断输入的几组数据是否有同性恋 思路:http://blog.csdn.net/iaccepted/article/details/24304087 分组并查 ...
- HDU 1198(并查集)
题意:给你11个图,每一个都有管道,然后给一张由这11个正方形中的n个组成的图,判断有几条连通的管道: 思路:在大一暑假的时候做过这道题,当时是当暴力来做的,正解是并查集,需要进行一下转换: 转换1: ...
随机推荐
- 7 定制10MINs首页2
1.添加 <div class="ui basic segment"> <h1 class="ui center aligned header" ...
- webstrom Certificate validation failed
今天好烦.因为装了一个webstrome,我的svn不管用了. 为了防止webstrom,我的日期改了,日期改了,csdn登不上去了.告诉我时期不对. 草草哦哦. 这就是那个svn出问题之后的画面. ...
- Robolectric
今天学习了单元测试框架,Robolectric.初步感觉,可能我测试的少,没有感觉Robolectric能有多大的帮助.虽然可以帮助创建activity.可以模拟点击事件.可是有什么呢. 好吧,讲下使 ...
- 每天一个Linux命令(2):shutdown命令
shutdown命令是系统关机命令.shutdown指令可以关闭所有程序,并依用户的需要,进行重新开机或关机的动作. 语法 shutdown(选项)(参数) 选项 -c:取消已经在进行的 shutdo ...
- winform-实现类似QQ停靠桌面上边缘隐藏的效果
//实现类似QQ停靠桌面上边缘隐藏的效果! private void timer1_Tick(object sender, EventArgs e) { System.Drawing.Point pp ...
- Spring 学习笔记(五)—— Bean之间的关系、作用域、自动装配
继承 Spring提供了配置信息的继承机制,可以通过为<bean>元素指定parent值重用已有的<bean>元素的配置信息. <?xml version="1 ...
- aes加密码
js地址 https://github.com/yves8888/crypto-js 下面src<!DOCTYPE html> <html lang="en"&g ...
- hdu 2510 符号三角形 (DFS+打表)
符号三角形 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- [bzoj3813] 奇数国 [线段树+欧拉函数]
题面 传送门 思路 这题目是真的难读......阅读理解题啊...... 但是理解了以后就发现,题目等价于: 给你一个区间,支持单点修改,以及查询一段区间的乘积的欧拉函数值,这个答案对19961993 ...
- unicode 编码在线转换工具--javascript
http://www.cnblogs.com/mq0036/p/4007452.html