HDU 3018 Ant Trip

Source: Internet
Author: User

Ant Trip

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): Accepted submission (s): 785


problem DescriptionAnt country consist of N towns. There is M roads connecting the towns.

Ant Tony,together with He friends,wants to go through every part of the country.

They intend to visit every road, and every road must is visited for exact one time. However,it May is a mission impossible for only one group of people. So they is trying to divide all the people into several groups,and each could start at different town. Now, Tony wants to know, what's the least groups of ants, needs to form to achieve their goal.

InputInput contains multiple cases. Test cases is separated by several blank lines. Each test case is starts with the integer n (1<=n<=100000), M (0<=m<=200000), indicating that there is N towns and M Roads in Ant country.followed by M Lines,each line contains b integers a, (1<=a,b<=n) indicating that there is a Road connecting Town A, and town b.no, roads'll be, the Same,and there is No road connecting the same town.

OutputFor each test case, the output of the least groups that needs to form to achieve their goal.

Sample Input3 31 22 31 3 4 21 23 4

Sample Output12 HintNew ~ ~ ~ Notice:if There is no road connecting one town, Tony could forget about the town. In sample 1,tony and he friends just form one group,they can start at either Town 1,2,or 3.In sample 2,tony and his Frien DS must form the group.

SourceMulti-university Training Contest 12-host by Fzu problem Solving: The determination of Euler circuit
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =100010;4 intUF[MAXN],D[MAXN],ODD[MAXN];5 BOOLVIS[MAXN];6 intFind (intx) {7     if(x = uf[x]) uf[x] =Find (uf[x]);8     returnUf[x];9 }Tenvector<int>Root; One intMain () { A     intn,m,u,v; -      while(~SCANF ("%d%d",&n,&m)) { -          for(inti =0; i < MAXN; ++i) { theUf[i] =i; -Odd[i] = D[i] =0; -Vis[i] =false; -         } + root.clear (); -          for(inti =0; I < m; ++i) { +scanf"%d%d",&u,&v); A++D[u]; at++D[v]; -U =Find (u); -v =Find (v); -             if(U = v) uf[v] =u; -         } -          for(inti =1; I <= N; ++i) { inU =Find (i); -             if(!Vis[u]) { toVis[u] =true; + root.push_back (u); -             } the             if(d[i]&1) ++Odd[u]; *         } $         intRET =0;Panax Notoginseng          for(inti =0; I < root.size (); ++i) { -             if(!d[root[i]])Continue; the             if(Odd[root[i]] = =0) ret++; +             ElseRET + = odd[root[i]]/2; A         } theprintf"%d\n", ret); +     } -     return 0; $}
View Code

HDU 3018 Ant Trip

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.