只输出0求调
  • 板块灌水区
  • 楼主Fake_Cry
  • 当前回复6
  • 已保存回复6
  • 发布时间2024/10/1 15:33
  • 上次更新2024/10/1 16:36:55
查看原帖
只输出0求调
891975
Fake_Cry楼主2024/10/1 15:33

题目传送门

#include<bits/stdc++.h>
using namespace std;
const int N=1e4+10;
int dist[N];
int vis[N],mp[N][N];
int dijstra(int n){
	memset(dist,0x3f,sizeof dist);
	dist[1]=0;
	for(int i=1;i<=n;i++){
		int index=-1;
		for(int j=1;j<=n;j++){
			if(!vis[j]&&(dist[j]<dist[index]||index==-1)){
				index=j;
			}
		}
		vis[index]=1;
		for(int j=1;j<=n;j++){
			dist[j]=min(dist[j],dist[index]+mp[index][j]);
		}
	}
	if(dist[n]==0x3f3f3f3f) return (1<<31)-1;
	else return dist[n];
}
int main(){
	int n,m,s;
	cin>>n>>m>>s;
	while(m--){
		int a,b,c; cin>>a>>b>>c;
		mp[a][b]=c;
	}
	cout<<dijstra(s)<<endl;
	return 0;
}
2024/10/1 15:33
加载中...