-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCF_FldWars.cpp
More file actions
55 lines (41 loc) · 829 Bytes
/
CF_FldWars.cpp
File metadata and controls
55 lines (41 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//https://codeforces.com/problemset/problem/295/B
#include<bits/stdc++.h>
using namespace std;
const int N = 510;
long long dist[N][N];
int main()
{
int n;
cin>>n;
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
cin>>dist[i][j];
}
}
vector<int> del_order(n);
for(int i=0; i<n; i++){
cin>>del_order[i];
}
reverse(del_order.begin(), del_order.end());
vector<long long> ans;
for(int k=0; k<n; k++){
int k_v = del_order[k];
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
dist[i][j]=min(dist[i][j], dist[i][k_v] + dist[k_v][j]);
}
}
long long sum =0;
for(int i=0; i<=k; i++){
for(int j=0; j<=k; j++){
sum += dist[del_order[i]][del_order[j]];
}
}
ans.push_back(sum);
}
reverse(ans.begin(), ans.end());
for(auto val : ans){
cout<<val<<endl;
}
return 0;
}