Hamilton
시간 제한2초메모리 제한512 MB
부모 포인터로 주어진 트리에서 연속한 마을 사이 거리가 3 이하이면서 모든 마을을 정확히 한 번씩 방문하는 해밀턴 경로를 찾거나, 불가능하면 NO를 출력한다.
문제
Tracker Smurf is planning his trip for next holidays. He wants to spend exactly one night in each of the villages in SmurfLand. His trip can start and end in any village. Villages in SmurfLand are connected by roads in such a way that there's exactly one path between any two villages. The distance between any two directly connected villages is exactly one kilometer. Tracker is so fast that he can travel up to three kilometers each day, but he is still not sure if that's enough to be able to spend a night in each village exactly once. Help him find the answer.
입력
First line of input contains an integer () -- the number of villages in SmurfLand. The next lines describe the roads. th input line () contains an integer () which means that there is a road connecting villages and .
출력
On a single line output integers () specifying the sequence of villages for Tracker to spend the nights in (Tracker starts in village then goes to village and so on, finishing in village ). If it is not possible to plan Tracker's trip then on a single line output the word "NO" (without quotes).