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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
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): . 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): . 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.