아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Watchcow

시간 제한1초메모리 제한1024 MB

요약
1번 목장에서 시작하고 끝나며 각 무향 길을 양방향으로 정확히 한 번씩 지나는 닫힌 경로를 찾는다.
난이도

보통10점 중 7점

유형
그래프, DFS
정답자
아직 제출이 없습니다

문제

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 are doing any evil. She begins at the barn, makes her patrol, and then returns to the barn when she's done.

If she were a more observant cow, she might be able to just walk each of M (1 ≤ M ≤ 50,000) bidirectional trails numbered 1..M between N (2 ≤ N ≤ 10,000) fields numbered 1..N on the farm once and be confident that she's seen everything she needs to see. But since she isn't, she wants to make sure she walks down each trail exactly twice. It's also important that her two trips along each trail be in opposite directions, so that she doesn't miss the same thing twice.

A pair of fields might be connected by more than one trail. Find a path that Bessie can follow which will meet her requirements. Such a path is guaranteed to exist.

입력

  • Line 1: Two integers, N and M.
  • Lines 2..M+1: Two integers denoting a pair of fields connected by a path.

출력

  • 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 is possible, output any solution.

예제1

  1. 예제 1

    입력
    4 5
    1 2
    1 4
    2 3
    2 4
    3 4
    
    예상 출력
    1
    2
    3
    4
    2
    1
    4
    3
    2
    4
    1