"CodeVS2039" horse-repairing fence

Source: Internet
Author: User

Description

Farmer John has a lot of fences to fix every year. He always rode a horse through every fence and repaired the place where it was broken.

John is a man as lazy as the other peasants. He hates riding, so he never passes a fence twice. You have to make up a program, read the description of the fence network, and figure out a path to fix the fence so that every fence happens once. John can start horseback riding from any vertex (that is, the intersection of two fences), ending at any one vertex.

Each fence connects two vertices, and vertices are labeled 1 to 500 (although some farms do not have 500 vertices). Any number of (>=1) fences can be connected at one vertex. There may be multiple fences between the two vertices. All fences are connected (i.e. you can reach all other fences from any fence).

Your program must output the path of the ride (indicated by the vertex number that passes through the road). If we think of the output path as a number of 500, then when there are multiple sets of solutions, the smallest of the output 500 binary notation (that is, the output of the first number of smaller, if there is more than one set of solutions, the output of the second number of smaller, and so on).

Input data is guaranteed to have at least one solution.

Input

Line 1th: An integer f (1 <= F <= 1024), indicating the number of fences

Line 2nd to f+1: Two integers per line I, j (1 <= i,j <= 500) indicate that the fence connects I with the J Vertex.

Output

The output should have f+1 lines, an integer per line, which in turn represents the vertex number that the path passes through. Note that the data may have multiple sets of solutions, but only the set of solutions required by the above topic is considered correct.

Sample Input
91 22 33 44 24 52 55 65 74 6
Sample Output
1234254657
Exercises

It's a European road.

Actually, I wrote it wrong at first.

void Find (int  x) {    for (int i=1; i<=n;i++)         if  (E[i][x]) {            e[i][x]--;e[x][i]--;d is[++cnt]=x;find (i);}        }
It's written like this bear.
#include <iostream>#include<cstdio>using namespacestd;Const intf=1030;Const intn=510;intE[f][f];intDis[n];intDu[n];intf,s=100000000, cnt=0, N,x,y;voidFindintx) {     for(intI=1; i<=n;i++)        if(E[i][x]) {e[i][x]--;e[x][i]--; find (i); } dis[++cnt]=x;}intMain () {scanf ("%d",&f);  for(intI=1; i<=f;i++) {scanf ("%d%d",&x,&y); E[x][y]++;e[y][x]++; DU[X]+ +;d u[y]++; N=max (n,x); n=Max (n,y); S=min (s,x); s=min (s,y); }     for(intI=1; i<=n;i++)        if(du[i]%2) {s=i; Break;    } find (s);  for(inti=cnt;i>=1; i--) printf ("%d\n", Dis[i]);}

"CodeVS2039" horse-repairing fence

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.