UVa 10596 moring Walk "Euler circuit"

Source: Internet
Author: User

Test instructions: Give n points, M road, ask whether can go through M road.

When I do it = = nimbly with and check the set made, WA a pitch-and then WA a few hair-(and also to judge the connectivity of AH)

Search the Puzzle = = found to be this:

Because it is only required to walk all the way, that is, just to finish the road that has been given, and there is no requirement that all the points along the way,

For example, given the way to have these

0 1

1 2

2 3

3 0

4 4

Then the road is formed, walking round the blue line in the picture, that is, to walk all the way,

and 4 is an outlier, and it does not constitute a road, so it does not need to be taken care of.

The IF (d[i]!=0) in the code is to determine if the point is an outlier.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 intd[10010],pre[10010];7 intFindintRoot) {returnRoot = = Pre[root]? Root:pre[root] =find (Pre[root]);}8 voidUnionroot (intXinty)9 {Ten     introot1=find (x); One     intRoot2=find (y); A     if(Root1!=root2) pre[root1]=Root2; - } -  the intMain () - { -     intm,n,u,v,i; -      while(SCANF ("%d%d", &n,&m)! =EOF) +     { -             intflag=1; +memset (D,0,sizeof(d)); Amemset (PRE,0,sizeof(pre)); at          for(i=0; i<=10010; i++) -pre[i]=i; -          for(i=1; i<=m;i++) -         { -scanf"%d%d",&u,&v); -d[u]++; ind[v]++; - Unionroot (u,v); to         } +          -         intRoot=find (0); the          *         if(m==0|| n==0) flag=0;//n=0 can not form a circuit, m=0 time can not $         Panax Notoginseng          for(i=0; i<n;i++){      -                 if(d[i]!=0){//determine if this point is an isolated point the                     if(Find (i)!=root| | d[i]%2!=0){//determine if the point is on the same unicom block, and whether the store has an even number of degrees +flag=0; A                      Break; the                   } +                 }  -         } $          $         if(flag) -printf"possible\n"); -         Else theprintf"Not possible\n");  -     }Wuyi     return 0; the}
View Code

She just wants to go all the way, she doesn't want to go 4

Go---go---

UVa 10596 moring Walk "Euler 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.