PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000062. Chim xanh (Blue Bird)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chim xanh (Blue Bird)
Blue Bird
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Roads are undirected with positive lengths. Starting at house 1, visit another house and return to house 1 without traversing the same road twice. Minimize total length, or report -1 if no valid trip exists.
Input
First n m; then m undirected roads u v length (1-based), with distinct unordered endpoints.
Output
Print the minimum total route length, or -1 if impossible.
Subtasks
- Subtask 1 (40 points): . For each road, 1 <= u < v <= n. The undirected graph has no duplicate unordered endpoint pair.
- Subtask 2 (60 points): $3\le n\le 300,\ 0\le m\le n(n-1)/2,\ 1\le w\le 10^5$. For each road, 1 <= u < v <= n. The undirected graph has no duplicate unordered endpoint pair.
Examples
Input
4 4
1 2 3
2 3 4
1 3 5
1 4 1
Output
12
Explanation
Cycle 1→2→3→1 uses distinct roads with total length 3+4+5=12. The road 1–4 cannot contribute to a valid cycle; traversing it out and back would reuse the same road.