HDU Ant Trip
来源:互联网 发布:mysql登录密码设置密码 编辑:程序博客网 时间:2024/06/05 15:21
Ant Trip
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2909 Accepted Submission(s): 1164
Problem Description
Ant Country consist of N towns.There are M roads connecting the towns.
Ant Tony,together with his friends,wants to go through every part of the country.
They intend to visit every road , and every road must be visited for exact one time.However,it may be a mission impossible for only one group of people.So they are trying to divide all the people into several groups,and each may start at different town.Now tony wants to know what is the least groups of ants that needs to form to achieve their goal.
Ant Tony,together with his friends,wants to go through every part of the country.
They intend to visit every road , and every road must be visited for exact one time.However,it may be a mission impossible for only one group of people.So they are trying to divide all the people into several groups,and each may start at different town.Now tony wants to know what is the least groups of ants that needs to form to achieve their goal.
Input
Input contains multiple cases.Test cases are separated by several blank lines. Each test case starts with two integer N(1<=N<=100000),M(0<=M<=200000),indicating that there are N towns and M roads in Ant Country.Followed by M lines,each line contains two integers a,b,(1<=a,b<=N) indicating that there is a road connecting town a and town b.No two roads will be the same,and there is no road connecting the same town.
Output
For each test case ,output the least groups that needs to form to achieve their goal.
Sample Input
3 31 22 31 34 21 23 4
Sample Output
12HintNew ~~~ Notice: if there are no road connecting one town ,tony may forget about the town.In sample 1,tony and his friends just form one group,they can start at either town 1,2,or 3.In sample 2,tony and his friends must form two group.
Source
2009 Multi-University Training Contest 12 - Host by FZU
Recommend
gaojie
#include<stdio.h>#include<string.h>#define MAX1 100000+10int num[MAX1],odd[MAX1];int n,m;int fa[MAX1],degree[MAX1];int findset(int i){if(fa[i]==-1)return i;return fa[i]=findset(fa[i]);}int main(){while(~scanf("%d %d",&n,&m)){memset(degree,0,sizeof(degree));memset(fa,-1,sizeof(fa));memset(num,0,sizeof(num));memset(odd,0,sizeof(odd));int i,sum=0,x,y;for(i=0;i<m;i++){scanf("%d %d",&x,&y);degree[x]++,degree[y]++; y=findset(y), x=findset(x); if(y!=x) fa[y]=x;}for(i=1;i<=n;i++){num[findset(i)]++; //num[i]=x表以i为根的连通分量中有x个节点 if(degree[i]%2) odd[findset(i)]++;}for(i=1;i<n;i++){if(num[i]<=1)continue;else if(odd[i]==0)sum++;else if(odd[i]>1)sum+=odd[i]/2;}printf("%d\n",sum);}return 0;}
阅读全文
0 0
- hdu 3018 Ant Trip
- HDU-3018-Ant Trip
- hdu 3018 Ant Trip
- hdu 3018 Ant Trip
- hdu 3018 Ant Trip
- HDU 3018 Ant Trip
- HDU 3018 Ant Trip
- Hdu 3018 Ant Trip
- HDU 3018 Ant Trip
- HDU 3018 Ant Trip
- hdu 3018 Ant Trip
- HDU 3018Ant Trip
- HDU Ant Trip
- hdu 3018 Ant Trip
- Ant Trip HDU
- HDU 3018 Ant Trip HDU
- hdu acm 3018 Ant Trip
- hdu acm 3018 Ant Trip
- 新人产品分析——第三步(2)
- Problem H: 稀疏矩阵的表示和运算
- /bin/bash^M: 坏的解释器: 没有那个文件或目录
- C语言的存储类别
- 一个SQL语句
- HDU Ant Trip
- 24. OP-TEE驱动篇----驱动编译,加载和初始化(一)
- 再谈 CSS 预处理器
- web工程相关问题
- http错误 404,500,400,503,405
- CodeForces 148D
- 去掉字符串左右两边的空格
- 新人产品分析——第三步(3)
- 跳棋的挑战