AC了
2024-06-29 14:42:13
发布于:浙江
5阅读
0回复
0点赞
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 30
using namespace std;
int n,k;
int map[MAXN][MAXN];
int main(){
memset(map,0x3f,sizeof(map));
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++){
int x;
scanf("%d",&x);
map[i][i%n+1]=map[i%n+1][i]=x;
}
for(int i=1;i<=k;i++){
char a,b;int x;
cin>>a>>b>>x;
if(map[a-'A'+1][b-'A'+1]<1000) map[a-'A'+1][b-'A'+1]=map[b-'A'+1][a-'A'+1]=max(map[a-'A'+1][b-'A'+1],x);
else map[a-'A'+1][b-'A'+1]=map[b-'A'+1][a-'A'+1]=x;
}
for(int i=1;i<=n;i++)
if(map[i][i]>1000) map[i][i]=0;
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i!=j&&i!=k&&j!=k&&map[i][j]>map[i][k]+map[k][j])
map[j][i]=map[i][j]=map[i][k]+map[k][j];
char a,b;
cin>>a>>b;
cout<<map[a-'A'+1][b-'A'+1];
}
这里空空如也
有帮助,赞一个