#FW0000084. Đường mới tại Berland (Roads in Berland)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đường mới tại Berland (Roads in Berland)
Roads in Berland
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given a connected undirected network represented by its current shortest-distance matrix, sequentially add roads . After each addition print the sum of shortest distances across unordered pairs . Non-improving edges leave the sum unchanged.
Input
First , a symmetric all-pairs shortest-distance matrix with zero diagonal, then new roads (1-based).
Output
Print space-separated integer sums after consecutive road additions.
Subtasks
-
Subtask 1 (40 points): . , ma trận đối xứng và đã là ma trận đường đi ngắn nhất; .
-
Subtask 2 (60 points): . , ma trận đối xứng và đã là ma trận đường đi ngắn nhất; .
Examples
Input
3
0 2 5
2 0 3
5 3 0
2
1 3 2
1 2 8
Output
7 7
Explanation
The initial unordered-pair sum is 10. Adding edge 1–3 of length 2 reduces it to 7; the second edge of length 8 does not improve the network.