POJ 2230 Watchcow

Source: Internet
Author: User

Watchcowtime limit:3000msmemory limit:65536kbthis problem'll be judged onPKU. Original id:2230
64-bit integer IO format: %lld Java class name: Main Bessie ' s been appointed the new Watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no evildoers is doing any evil. She begins at the barn, makes his patrol, and then returns to the barn when she's done.

If She were a more observant cow, she might being able to just walk each of M (1 <= M <= 50,000) bidirectional trails N Umbered 1..M between N (2 <= n <=) fields numbered 1..N on the farm once and is confident that she ' s seen Eve Rything she needs to see. But since she is ' t, she wants to make sure she walks down each trail exactly twice. It's also important that she's the trips along each trail is in opposite directions, so, she doesn ' t miss the same thing Twice.

A pair of fields might is connected by more than one trail. Find a path that Bessie can follow which would meet her requirements. Such a path is guaranteed to exist. Input* Line 1:two integers, N and M.

* Lines 2..m+1:two integers denoting a pair of fields connected by a path.Output* Lines 1..2m+1:a List of fields she passes through, one per line, beginning and ending with the Barn at Field 1. If more than one solution are possible, output any solution.Sample Input
4 51 21 42 32 43 4
Sample Output
12342143241
HintOUTPUT DETAILS:

Bessie starts at 1 (barn), goes to 2, then 3, etc ...SourceUsaco 2005 January Silver Problem solving: Euler circuit
1#include <cstdio>2#include <cstring>3 using namespacestd;4 Const intMAXN =10010;5 structArc {6     intTo,next;7Arcintx =0,inty =-1) {8to =x;9Next =y;Ten     } One} e[500000]; A inthead[maxn],tot,n,m; - BOOLvis[500000]; - voidAddintUintv) { theE[tot] =arc (V,head[u]); -Head[u] = tot++; - } - voidDfsintu) { +      for(int&i = Head[u]; ~i; i =E[i].next) { -         if(Vis[i])Continue; +Vis[i] =true; A DFS (e[i].to); at     } -printf"%d\n", u); - } - intMain () { -     intu,v; -      while(~SCANF ("%d%d",&n,&m)) { inmemset (head,-1,sizeofhead); -memset (Vis,false,sizeofvis); to          for(inti = tot =0; I < m; ++i) { +scanf"%d%d",&u,&v); - Add (u,v); the Add (v,u); *         } $Dfs1);Panax Notoginseng     } -     return 0; the}
View Code

POJ 2230 Watchcow

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.