#FW0000085. Greg và đồ thị (Greg and Graph)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Greg và đồ thị (Greg and Graph)
Greg and Graph
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given a directed complete nonnegative weighted graph and an order for deleting all vertices, output the sum of shortest-path distances over all ordered pairs of currently remaining vertices immediately before each deletion. Deleted vertices cannot be used as intermediates.
Input
First , then an directed cost matrix with zero diagonal, followed by a permutation giving the deletion order (1-based).
Output
Print integer sums in the original deletion order, separated by spaces.
Subtasks
-
Subtask 1 (40 points): . , nếu ; ma trận có hướng và mọi đỉnh đi tới nhau.
-
Subtask 2 (60 points): . , nếu ; ma trận có hướng và mọi đỉnh đi tới nhau.
Examples
Input
3
0 2 7
2 0 3
7 3 0
3 2 1
Output
20 4 0
Explanation
Before deleting vertex 3, the total shortest-distance sum across ordered pairs is 20. With vertices 1 and 2 remaining it becomes 4, and with one vertex it is 0.