PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000071. Khôi phục cạnh từ khoảng cách (Antifloyd)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Khôi phục cạnh từ khoảng cách (Antifloyd)
Antifloyd
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
Given all-pairs shortest distances of an undirected graph with positive integer edge weights, reconstruct a graph using the fewest edges, or print Need better measurements. if the measurements are inconsistent.
Input
First . For , row contains positive distances .
Output
If inconsistent, print Need better measurements.. Otherwise print the edge count followed by lines u v w, with in lexicographic order.
Subtasks
-
Subtask 1 (40 points): . , với , .
-
Subtask 2 (60 points): . , với , .
Examples
Input
3
2
5 3
Output
2
1 2 2
2 3 3
Explanation
The measured distances are 2, 5, and 3. The distance between 1 and 3 is realized via vertex 2, so only edges 1–2 and 2–3 are needed.