玄关求调
查看原帖
玄关求调
1223290
Lovelace_qwq楼主2024/7/29 08:45

代码:

#include<bits/stdc++.h>
using namespace std;
int n,m,s;
const int maxn=6e5;
struct node{
	int u,v;
	long long w;
}e[maxn];
long long dist[maxn];
int main(){
	cin>>n>>m>>s;
	for(int i=1;i<=m;i++)cin>>e[i].u>>e[i].v>>e[i].w;
	for(int i=1;i<=n;i++)dist[i]=(1ll<<31)-1;
	dist[s]=0;
	for(int i=1;i<n;i++){
		for(int j=1;j<=m;j++){
			if(dist[e[j].v]>dist[e[j].u]+e[j].w){
				dist[e[j].v]=dist[e[j].u]+e[j].w;
			}
		}
	}
	for(int i=1;i<=n;i++)cout<<dist[i]<<" ";
	return 0;
}
2024/7/29 08:45
加载中...