Ant Trip HDU-3018 (number of Oralu + and check set)

Source: Internet
Author: User

Test instructions

Ant Tony and his friends want to visit ants all over the country.

give you the Ant country's n points and M-bar, and now ask you at least a few strokes to draw all sides. ( Pen does not leave the paper when a stroke
Ensure that the M-edge is different and there is no self-ring edge at the same point.
That is, the ant group traverses the entire graph, and they try to divide all the people into groups, and each group can start with different towns.
Tony wants to know at least a few groups.

Input inputs contain multiple sets of test cases, separated by a number of empty rows.
The first line of each test case is two integers n (1<=n<=100000), M (0<=m<=200000), indicating that ants state n towns and M roads.
After the M-line, each line contains two integer u,v, (1<=u,v<=n, which indicates that there is a road connecting town U and Town v.
Output for each test case, the outputs need to form the minimum number of groups to achieve their goals. Sample Input

3 31 22 31 34 21 23 4

Sample Output

12

Analytical:
There is no guarantee that all points are a connected block, so there are three cases for each connected block
1, the current connected block each point of the number of degrees are even, that is, the European pull circuit so a pen on the line
2, there are X singularity points, known every two singularities can form a Euler path, so the number of strokes = X/2;
3, a single point becomes connected block so 0 pen
It's okay to use and check the block to maintain the connectivity.
#include <iostream>#include<cstdio>#include<sstream>#include<cstring>#include<map>#include<cctype>#include<Set>#include<vector>#include<stack>#include<queue>#include<algorithm>#include<cmath>#include<bitset>#defineRap (i, A, n) for (int i=a; i<=n; i++)#defineRep (I, A, n) for (int i=a; i<n; i++)#defineLap (I, a, n) for (int i=n; i>=a; i--)#defineLEP (i, A, n) for (int i=n; i>a; i--)#defineRD (a) scanf ("%d", &a)#defineRlld (a) scanf ("%lld", &a)#defineRC (a) scanf ("%c", &a)#defineRS (a) scanf ("%s", a)#definePD (a) printf ("%d\n", a);#definePlld (a) printf ("%lld\n", a);#definePC (a) printf ("%c\n", a);#definePS (a) printf ("%s\n", a);#defineMOD 2018#defineLL Long Long#defineULL unsigned long Long#definePair Pair<int, int>#defineMem (A, B) memset (A, B, sizeof (a))#define_ Ios_base::sync_with_stdio (0), Cin.tie (0)//freopen ("1.txt", "R", stdin);using namespacestd;Const intMAXN = 1e6 +Ten, INF =0x7fffffff, Ll_inf =0x7fffffffffffffff;intDEG[MAXN], F[MAXN], CNT[MAXN];Set<int>G;intFindintx) {    returnF[X] = = x? x: (F[x] =find (F[x]));}intMain () {intN, M;  while(Cin >> N >>m) { for(inti =1; I <= N; i++) F[i] =i; Mem (deg,0); MEM (CNT,0);        G.clear (); intu, v;  for(inti =1; I <= m; i++) {cin>> u >>v; intL =find (U); intR =Find (v); if(l! = r) F[l] =R; Deg[u]++; DEG[V]++; }         for(inti =1; I <= N; i++)        {            intx =find (i); if(Deg[i] &1) cnt[x]++;        G.insert (x); }        intres =0;  for(Set<int>::iterator it = G.begin (); It! = G.end (); it++)        {            intx = *it; if(Deg[x] = =0)Continue; if(Cnt[x] = =0) res++; ElseRes + = Cnt[x]/2; } cout<< Res <<Endl; }    return 0;}






Ant Trip HDU-3018 (number of Oralu + and check set)

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.