PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000061. Người quản lý hộp tiền — vòng di chuyển tối thiểu (USHER — Minimum Round 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
Người quản lý hộp tiền — vòng di chuyển tối thiểu (USHER — Minimum Round Trip)
USHER — Minimum Round Trip
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
A money box leaves the manager at vertex 1 and travels along directed transfers with positive costs. Find the minimum total cost of a nonempty closed walk that starts and ends at vertex 1, or -1 if none exists. This is an original PHOJ adaptation inspired by a minimum-cycle technique, NOT a translation of UVa 1233. This task is an original PHOJ adaptation, not the original UVa USHER statement.
Input
First n m; then m directed edges u v cost (1-based).
Output
Print the minimum positive closed-walk cost starting at vertex 1, or -1.
Subtasks
- Subtask 1 (40 points): . 1 <= u,v <= n and u != v. The graph is directed; parallel edges and disconnected components are allowed.
- Subtask 2 (60 points): . 1 <= u,v <= n and u != v. The graph is directed; parallel edges and disconnected components are allowed.
Examples
Input
3 4
1 2 2
2 3 3
3 1 4
1 3 10
Output
9
Explanation
The 1→2→3→1 closed walk costs 2+3+4=9; the 1→3→1 walk costs 10+4=14, so 9 is optimal.