Greg and Graph

题意翻译

# 题目描述 Greg 有一个有边权的有向图,包含 $n$ 个点。这个图的每两个点之间都有两个方向的边。Greg 喜欢用他的图玩游戏,现在他发明了一种新游戏: - 游戏包含 $n$ 步。 - 第 $i$ 步 Greg 从图中删掉编号为 $x_i$ 的点。当删除一个点时,这个点的出边和入边都会被删除。 - 在执行每一步之前,Greg 想知道所有点对间最短路长度的和。最短路可以经过任何没删掉的点。换句话说,如果我们假设 $d(i, v, u)$ 是在删掉 $x_i$ 前 $v$ 和 $u$ 间的最短路长度,那么Greg想知道下面这个求和的值:$\sum_{v, u, v \neq u} d(i, v, u)$ 。 帮帮 Greg,输出每一步之前要求的值。 # 输入格式 第一行包含一个整数 $n \ (1 \leq n \leq 500)$ ,代表图中的点数。 下面 $n$ 行每行包含 $n$ 个整数,代表边权:第 $i$ 行的第 $j$ 个数 $a_{ij} \ (1 \leq a_{ij} \leq 10^5, a_{ii} = 0)$ 代表从 $i$ 到 $j$ 的边权。 最后一行包含 $n$ 个整数:$x_1, x_2, \dots, x_n \ (1 \leq x_i \leq n)$ ,分别为Greg每一步删掉的点的编号。 # 输出格式 输出 $n$ 个整数,第 $i$ 个数等于游戏的第 $i$ 步之前统计的求和值。 请不要在 C++ 中使用 `%lld` 标志来输出 64 位整数 `long long`,推荐使用 `cin, cout` 流或者用 `%I64d` 标志。 Translated by @KSkun

题目描述

Greg has a weighed directed graph, consisting of $ n $ vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game: - The game consists of $ n $ steps. - On the $ i $ -th step Greg removes vertex number $ x_{i} $ from the graph. As Greg removes a vertex, he also removes all the edges that go in and out of this vertex. - Before executing each step, Greg wants to know the sum of lengths of the shortest paths between all pairs of the remaining vertices. The shortest path can go through any remaining vertex. In other words, if we assume that $ d(i,v,u) $ is the shortest path between vertices $ v $ and $ u $ in the graph that formed before deleting vertex $ x_{i} $ , then Greg wants to know the value of the following sum: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF295B/e705b87d1be14272a35a09cec23c216ee2b579b3.png). Help Greg, print the value of the required sum before each step.

输入输出格式

输入格式


The first line contains integer $ n $ $ (1<=n<=500) $ — the number of vertices in the graph. Next $ n $ lines contain $ n $ integers each — the graph adjacency matrix: the $ j $ -th number in the $ i $ -th line $ a_{ij} $ $ (1<=a_{ij}<=10^{5},a_{ii}=0) $ represents the weight of the edge that goes from vertex $ i $ to vertex $ j $ . The next line contains $ n $ distinct integers: $ x_{1},x_{2},...,x_{n} $ $ (1<=x_{i}<=n) $ — the vertices that Greg deletes.

输出格式


Print $ n $ integers — the $ i $ -th number equals the required sum before the $ i $ -th step. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.

输入输出样例

输入样例 #1

1
0
1

输出样例 #1

0 

输入样例 #2

2
0 5
4 0
1 2

输出样例 #2

9 0 

输入样例 #3

4
0 3 1 1
6 0 400 1
2 4 0 1
1 1 1 0
4 1 2 3

输出样例 #3

17 23 404 0