시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB943100.000%

문제

Byteasar is planning an excursion along Byteland. Some pairs of cities in Byteland are connected by bidirectional bus transportation. Byteasar would like his excursion to start and end in the same city and be the cheapest non-empty path that does not use the same bus connection more than once (after taking the route from A to B he doesn't want to use any of the connections: A -> B, B -> A any more). Write a program that finds the cheapest closed path along Byteland without any duplicate bus connections or determines that it is not possible to find any such path.

 

입력

The first line of the input contains two integers n and m (1 ≤ n ≤ 500, 0 ≤ m ≤ 50,000) separated with a single space that represent the number of cities in Byteland and the number of bidirectional bus connections between these cities. Each of the following m lines contains three integers xi, yi and ci (1 ≤ xi,yi ≤ n, xi ≠ yi, 1 ≤ ci ≤ 100,000): the starting city, the ending city and the cost of the i-th connection. Each pair of cities is connected by at most one such connection.

 

출력

The first line of the output should contain the number t of cities visited on the cheapest path (the starting city is counted twice). The next line should contain t space-separated integers: the numbers of cities visited on the path.

If there is more than one optimal solution, output any one of them. If there are no solutions, the first and only line of the output should contain a single word BRAK (Polish for none).

예제 입력 1

5 6
1 4 1
3 1 10
1 2 16
2 3 100
2 5 15
5 3 20

예제 출력 1

5
1 2 5 3 1

출처

Camp > POI Training Camp > ONTAK 2007 13번

  • 스페셜 저지를 만든 사람: koosaga