PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000092. Người bán hàng với cạnh âm (Negative Traveling Salesman)
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 bán hàng với cạnh âm (Negative Traveling Salesman)
Negative Traveling Salesman
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given a directed weighted graph with possibly negative edges but no negative cycles, find a walk visiting every vertex at least once with minimum total weight. Vertices and edges may be revisited. Print exactly No if no such walk exists.
Input
First line , followed by directed edges with 1-indexed vertices.
Output
Print the minimum total edge weight or No.
Subtasks
-
Subtask 1 (40 points): . All input-format and graph conditions above apply.
-
Subtask 2 (60 points): . All input-format and graph conditions above apply.
Examples
Input
2 1
1 2 -3
Output
-3
Explanation
Start at node 1 and take edge 1 to 2 with weight . Both nodes are visited, and there is no alternative walk of lower total cost, giving .