Hangzhou Electric 1878 Euro-pull circuit

Source: Internet
Author: User

DescriptionThe Euler circuit refers to a loop that does not leave the pen on paper, but only once per side of the picture and can return to the starting point. Now given a diagram, ask if there is a Euler circuit?InputThe test input contains several test cases. The 1th line of each test case gives two positive integers, namely the number of nodes N (1 < N < 1000) and the number of sides m, followed by M-bars, each with a pair of positive integers, the number of two nodes (nodes from 1 to N) that are directly connected to the bar. When n is 0 o'clock input knot
Beam.OutputThe output of each test case is one row, or output 1 if the Euler loop is present, otherwise output 0.Sample Input
3 31 21 32 33 21 22 30
Sample Output
10

The degree of each point is judged to be even, and no independent point is the Euler loop.

1#include <cstdio>2#include <string.h>3 intn,m,cnt,key,a,b,fa[1010],d[1010],i;4 intFindinta)5 {6     if(A = =Fa[a])7     {8         returnA;9     }Ten     Else One     { A         returnfa[a]=find (Fa[a]); -     } - } the voidF1 (intXinty) - { -     intNx,ny; -nx=find (x); +ny=find (y); -     if(NX! =NY) +     { Afa[ny]=NX; at     } - } - intMain () - { -      while(SCANF ("%d", &n) &&N) -     { inmemset (D,0,sizeof(d));//Array Clear 0 -          for(i =1; I <= N; i++) to         { +fa[i]=i; -         } thescanf"%d",&m); *          for(i =0; I < m; i++) $         {Panax Notoginsengscanf"%d%d",&a,&b); -d[a]++;  thed[b]++;//record the degree of each point + F1 (A, b);  A         } theCnt=0; key=0; +          for(i =1; i<= N; i++) -         { $             if(D[i]%2)//To judge that each point is an even degree $             { -key=1; -             } the             if(i = = Fa[i])//Judging there's no independent point -             {Wuyicnt++; the             } -         } Wu         if(CNT = =1)//There's no separate point -         { About             if(Key = =0)//each point has an even number of degrees $             { -printf"1\n"); -             } -             Else A             { +printf"0\n"); the             } -         } $         Else the         { theprintf"0\n"); the         } the     } -}

Hangzhou Electric 1878 Euro-pull circuit

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.