题解
代码
1 #include <cstdio>
2 #include <iostream>
3 #define ll long long
4 using namespace std;
5 const int N=1010;
6 int n,a[N][N],dis[N];
7 bool vis[N];
8 ll ans;
9 int main()
10 {
11 scanf("%d",&n);
12 for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) scanf("%d",&a[i][j]);
13 for (int i=1;i<=n;i++) scanf("%d",&dis[i]);
14 for (int i=1;i<=n;i++)
15 {
16 int x=0;
17 for (int j=1;j<=n;j++) if (!vis[j]&&(!x||dis[x]>dis[j])) x=j;
18 ans+=dis[x],vis[x]=1;
19 for (int j=1;j<=n;j++) if (!vis[j]&&dis[j]>a[x][j]) dis[j]=a[x][j];
20 }
21 printf("%lld",ans);
22 }