floyd全WA求调
查看原帖
floyd全WA求调
1145143
eggs_party楼主2025/1/18 12:00
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,u,v,w,a[1050][1050],ans;
signed main(){
	cin>>n>>m;
	memset(a,0x3f,sizeof(a));
	for(int i=1;i<=n;i++)a[i][i]=0;
	for(int i=1;i<=m;i++){
		cin>>u>>v>>w;
		a[u][v]=w;
	}
	
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
			}
		}
	}
	for(int i=2;i<=n;i++){
		ans+=a[1][i]+a[i][1];
	}
	cout<<ans;
	return 0;
}
2025/1/18 12:00
加载中...