Eccentric Excursion

시간 제한6초메모리 제한2048 MB

요약
도시 n개가 트리로 연결되어 있을 때, 트리 간선과 정확히 k개의 비트리 간선(항공편)을 사용해 모든 도시를 한 번씩 방문하는 순열 중 사전순으로 가장 작은 것을 구하거나 불가능하면 -1을 출력한다.
난이도

어려움10점 중 8점

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

문제

Eddy is planning a cross-country trip across nn different cities. There are n−1n-1 roads connecting the cities. Each road connects two cities and is bidirectional. The roads are laid out such that it is possible to travel between any two cities using only roads.

Eddy wants to plan a trip so that he visits each city exactly once. He may start or end at any city. It might not be possible to visit each city exactly once using only roads. Luckily, Eddy can take a flight between any two cities that aren't directly connected by a road. Eddy would like to take exactly kk flights during his trip.

Help Eddy plan his trip.

입력

The first line contains two integers n,kn, k (0≤k<n≤5000 \le k < n \le 500) where nn is the number of cities Eddy is visiting and kk is the number of flights Eddy would like to take.

The next n−1n-1 lines each contain two integers a,ba, b (1≤a<b≤n1 \le a < b \le n) indicating that there is a road between cities aa and bb. It is guaranteed it is possible to travel from any city to any other city only using roads.

출력

Output nn integers that specify the sequence of cities that Eddy shall visit in order. The sequence must visit each city exactly once and use exactly kk flights. If there are multiple possible itineraries, output the lexicographically smallest sequence. If there is no possible itinerary, output −1-1.

예제2

  1. 예제 1

    입력
    4 1
    1 2
    1 3
    1 4
    
    예상 출력
    2 1 3 4
    
  2. 예제 2

    입력
    4 0
    1 2
    1 3
    1 4
    
    예상 출력
    -1