【一笔画问题(多图,无向图)】Ant Trip

Ant Trip

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2030    Accepted Submission(s): 788


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.
 

 

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 3
1 2
2 3
1 3

4 2
1 2
3 4

 

 

Sample Output
1
2
 
 
题目大意:
  一笔画问题, 给你点和边的情况(能够构成一幅或者多幅图),问你最少需要几笔画,把所给的边画完。每条边有且仅有经过一次。
 
解法:
  一笔画问题(无向图):
  1,用并查集先判断有多少个图,保存每一幅图的根节点
  2,对于每一幅图,只需要统计它所包含的点的度和点的数量。
  3,根据每一幅图判断,能否构成欧拉路径,能的画则只需要一笔,不能的画,则需要(奇数度的点的个数/2);
  4,孤立点不算一笔,对于每一幅图判断点数量为1或者点的度是均为0,则可判断该图为孤立点,不进入计算、
posted @ 2015-08-14 10:18  Wurq  阅读(407)  评论(0编辑  收藏  举报