10165_RidingtheFences

2022-5-16 18:16| 发布者: Hocassian| 查看: 62| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-3-89504618124000-Problem List-采集的数据-后羿采集器.html

Pro.ID

10165

Title

Riding the Fences

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=10165

AC

12

Submit

44

Ratio

27.27%

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Farmer John owns a large number of fences that must be repaired annually. He traverses the fences by riding a horse along each and every one of them (and nowhere else) and fixing the broken parts.

    Farmer John is as lazy as the next farmer and hates to ride the same fence twice. Your program must read in a description of a network of fences and tell Farmer John a path to traverse each fence length exactly once, if possible. Farmer J can, if he wishes, start and finish at any fence intersection.

    Every fence connects two fence intersections, which are numbered inclusively from 1 through 500 (though some farms have far fewer than 500 intersections). Any number of fences (≥1) can meet at a fence intersection. It is always possible to ride from any fence to any other fence (i.e., all fences are "connected").

    Your program must output the path of intersections that, if interpreted as a base 500 number, would have the smallest magnitude.

    There will always be at least one solution for each set of input data supplied to your program for testing.

    输入

    Multiple test cases. For each case:

    Line 1:            The number of fences, F ( 1 ≤ F ≤ 1024 )

    Line 2..F+1:    A pair of integers ( 1 ≤ i, j ≤ 500 ) that tell which pair of intersections this fence connects.

    输出

    Description

    Farmer John owns a large number of fences that must be repaired annually. He traverses the fences by riding a horse along each and every one of them (and nowhere else) and fixing the broken parts.

    Farmer John is as lazy as the next farmer and hates to ride the same fence twice. Your program must read in a description of a network of fences and tell Farmer John a path to traverse each fence length exactly once, if possible. Farmer J can, if he wishes, start and finish at any fence intersection.

    Every fence connects two fence intersections, which are numbered inclusively from 1 through 500 (though some farms have far fewer than 500 intersections). Any number of fences (≥1) can meet at a fence intersection. It is always possible to ride from any fence to any other fence (i.e., all fences are "connected").

    Your program must output the path of intersections that, if interpreted as a base 500 number, would have the smallest magnitude.

    There will always be at least one solution for each set of input data supplied to your program for testing.

    Input

    Multiple test cases. For each case:

    Line 1:            The number of fences, F ( 1 ≤ F ≤ 1024 )

    Line 2..F+1:    A pair of integers ( 1 ≤ i, j ≤ 500 ) that tell which pair of intersections this fence connects.

    Output

    For each case, output  F+1 lines, each containing a single integer. Print the number of the starting intersection on the first line, the next intersection's number on the next line, and so on, until the final intersection on the last line. There might be many possible answers to any given input set, but only one is ordered correctly.

    Output a blank line after each case.

    Sample Input

    9
    1 2
    2 3
    3 4
    4 2
    4 5
    2 5
    5 6
    5 7
    4 6

    Sample Output
    1
    2
    3
    4
    2
    5
    4
    6
    5
    7

    Source

    样例输入

    9
    1 2
    2 3
    3 4
    4 2
    4 5
    2 5
    5 6
    5 7
    4 6

    样例输出

    1
    2
    3
    4
    2
    5
    4
    6
    5
    7

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部