PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000063. Chuyến tham quan ngắn nhất (Sightseeing Trip)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chuyến tham quan ngắn nhất (Sightseeing Trip)

Sightseeing Trip

Source: Timus

Version: Phuoc Hung OJ Extended

Problem Statement

Find a minimum-weight simple cycle in an undirected weighted graph. At least three distinct vertices must occur in the cycle; using the same road pair twice is not a cycle. Output any minimum cycle as a sequence of vertices.

Input

First n m; then m undirected edges u v weight (1-based, u != v).

Output

Print exactly No solution. if acyclic; otherwise output vertices of any minimum-weight simple cycle, space-separated and without repeating the initial vertex.

Subtasks

  • Subtask 1 (40 points): 3≤n≤8, 0≤m≤16, 1≤w≤1003\le n\le 8,\ 0\le m\le 16,\ 1\le w\le 100. For each road, 1 <= u,v <= n and u != v. The graph is undirected; parallel roads are allowed. A valid cycle has at least 3 distinct vertices.
  • Subtask 2 (60 points): 3≤n≤100, 0≤m≤1000, 1≤w≤1053\le n\le 100,\ 0\le m\le 1000,\ 1\le w\le 10^5. For each road, 1 <= u,v <= n and u != v. The graph is undirected; parallel roads are allowed. A valid cycle has at least 3 distinct vertices.

Examples

Input

4 4
1 2 2
2 3 3
1 3 4
3 4 10

Output

3 1 2

Explanation

Triangle 1–2–3–1 weighs 2+3+4=9. Vertex 4 has degree one and cannot belong to a cycle. Any rotation or reversal of the triangle is valid.