hdu 3047 Zjnu Stadium
来源:互联网 发布:大表妹是什么网络意思 编辑:程序博客网 时间:2024/05/23 14:07
Zjnu Stadium
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3352 Accepted Submission(s): 1299
Problem Description
In 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.
Input
There are many test cases:
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
For every case:
Output R, represents the number of incorrect request.
Sample Input
10 10
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
Sample Output
2
Hint
Hint:
(PS: the 5th and 10th requests are incorrect)
Source
2009 Multi-University Training Contest 14 - Host by ZJNU
【分析】
带权并查集…
【代码】
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define ll long long#define M(a) memset(a,0,sizeof a)#define fo(i,j,k) for(i=j;i<=k;i++)using namespace std;const int mxn=100005;int n,m;int dis[mxn],father[mxn];inline int find(int x){ if(x==father[x]) return father[x]; int fa=father[x]; father[x]=find(father[x]); dis[x]+=dis[fa]; return father[x];}int main(){ int i,j,a,b,c; while(scanf("%d%d",&n,&m)!=EOF) { int ans=0; fo(i,1,n) father[i]=i; memset(dis,0,sizeof dis); while(m--) { scanf("%d%d%d",&a,&b,&c); int fa=find(a),fb=find(b); if(fa!=fb) { father[fb]=fa; dis[fb]=dis[a]+c-dis[b]; } else if(dis[b]-dis[a]!=c) ans++; } printf("%d\n",ans); } return 0;}
- HDU 3047 Zjnu Stadium
- hdu 3047 Zjnu Stadium
- hdu 3047 Zjnu Stadium
- HDU 3047 Zjnu Stadium
- hdu 3047 Zjnu Stadium
- hdu 3047:Zjnu Stadium
- hdu 3047 Zjnu Stadium
- HDU-3047-Zjnu Stadium
- hdu 3047 Zjnu Stadium
- 【38.63%】【hdu 3047】Zjnu Stadium
- HDU 3047 Zjnu Stadium - 并查集
- HDU 3047 Zjnu Stadium [并查集]
- HDU Zjnu Stadium
- Zjnu Stadium HDU
- Hdoj 3047 Zjnu Stadium
- HDU 3047 Zjnu Stadium (带权并查集)
- hdu 3047 Zjnu Stadium(带权并查集)
- hdu 3047 Zjnu Stadium (带权并查集)
- 78. Spring Boot完美使用FastJson解析JSON数据【从零开始学Spring Boot】
- 实现发送短信验证码后60秒倒计时
- spingMVC关于@RequestMapping的几种用法
- Spring构建微服务
- 大型分布式网站术语分析
- hdu 3047 Zjnu Stadium
- 3ds Max 2014 SDK配置开发环境以及遇到的问题
- 第十章:DOM(DOM操作技术)
- 2017-4-19 离职感悟
- 产品建设三步骤
- @SerializedName注解
- [Leetcode] 98. Validate Binary Search Tree 解题报告
- LVS:三种负载均衡方式比较+另三种负载均衡方式
- Java实例化的几种方式