hud3018 解題報告

來源:互聯網
上載者:User
Ant Trip

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


Problem DescriptionAnt 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.

 


InputInput 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. 


OutputFor 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 sample3 2,tony and his friends must form two group.其實,先用並查集,分成幾個部分,然後,把每個部分的奇點數相加除2就可以,也就是說,分的組數和奇數點的個數的一半相等,不過要注意只有一個點的集合,不能算,要被怱略掉,才行,這一點,我錯了好幾次, 
 

#include <iostream>#include <vector>#include <stdio.h>using namespace std;int down[100005],setnum[100005],in[100005],re[100005],num[100005];bool zh[100005];int fin(int x){      if(down[x]!=x)      {            down[x]=fin(down[x]);      }      return down[x];}int main(){      int n,m,k,a,b,i,s,e,j,temp;      while(~scanf("%d%d",&n,&m))      {            for(i=0;i<=n;i++)            {                  zh[i]=true;                  num[i]=0;                  in[i]=0;                  down[i]=i;            }            while(m--)            {                  scanf("%d%d",&s,&e);                  a=fin(s);                  b=fin(e);                  if(a!=b)                  {                        down[a]=b;                  }                  in[s]++;                  in[e]++;            }             bool zhe;            int sum=0,ans;            for(i=1,j=1;i<=n;i++)            {                  temp=fin(i);                  zh[temp]=false;                  if(in[i]%2)                  {                      num[temp]++;                  }            }                 for(i=1;i<=n;i++)                 {                       if((zh[i]==false)&&(num[i]==0))                       {                             if(in[fin(i)])                              sum++;                       }                       else if((zh[i]==true)&&(num[i]==0))                       {                          continue;                       }                       else                       {                             sum+=num[i]/2;                       }                 }            printf("%d\n",sum);      }    return 0;}


Source2009 Multi-University Training Contest 12 - Host
by FZU

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.