• hdu3018欧拉回路题


    Ant Trip

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

    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 #include <iostream>
     2 #include <stdio.h>
     3 #include <algorithm>
     4 #include <string.h>
     5 #include <math.h>
     6 #include <vector>
     7 #include <stack>
     8 using namespace std;
     9 #define ll long long int
    10 int a[110000];
    11 int aa[100005];
    12 int find(int x)
    13 {
    14     while(x!=a[x])x=a[x];
    15     return x;
    16 }
    17 int main()
    18 {
    19     int n,m;
    20     while(scanf("%d%d",&n,&m)!=EOF)
    21     {
    22         memset(aa,0,sizeof(aa));
    23         int i,x,y;
    24         int b[n+1];
    25         for(i=1; i<=n; i++)
    26             a[i]=i;
    27         memset(b,0,sizeof(b));
    28         for(i=0; i<m; i++)
    29         {
    30             scanf("%d%d",&x,&y);
    31             b[x]++;
    32             b[y]++;
    33             int fx=find(x);
    34             int fy=find(y);
    35             if(fy!=fx)
    36                 a[fy]=fx;
    37         }
    38         int sum=0;
    39         for(i=1; i<=n; i++)
    40         {
    41             if(b[i]&1)
    42                 aa[find(a[i])]++;
    43         }
    44         for(i=1; i<=n; i++)
    45         {
    46             int tt=find(a[i]);
    47             if(b[i]&&tt==i)
    48             {
    49                 if(aa[tt])
    50                     sum+=aa[tt]/2;
    51                 else sum++;
    52             }
    53         }
    54         cout<<sum<<endl;
    55     }
    56 
    57 }
    View Code
  • 相关阅读:
    Python中循环引用(import)失败的解决方法
    junit中线程需要注意的问题
    python动态绑定属性和方法
    python输出缓冲区的问题
    使用RateLimiter完成简单的大流量限流,抢购秒杀限流
    guava的限流工具RateLimiter使用
    高性能分布式锁-redisson的使用
    正则表达式
    input 标签鼠标放入输入框补全提示
    Google guava工具类的介绍和使用
  • 原文地址:https://www.cnblogs.com/ERKE/p/3257384.html
Copyright © 2020-2023  润新知