全re求助
查看原帖
全re求助
910990
yswc223楼主2023/11/17 11:02

大佬们这段代码为什么全re了

#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5,INF=2147483647,M=1e4+5;
typedef pair<int,int> PII;
long long n,m,s;
long long dist[M];
bool st[M];
struct edge{
	int f,t,w;
	edge(int a,int b,int c){
		f=a,t=b,w=c;
	}
};
vector<edge> e[N];
int dijkstra(){
	for(int i=1; i<=n; i++)
		dist[i]=INF;
	dist[1] = 0;
	priority_queue<PII,vector<PII>,greater<PII> > heap;
	heap.push({1,0});
	while(heap.size()){
		auto t=heap.top();
		heap.pop();
		int x=t.first,y=t.second;
		if(st[x]) continue;
		st[x] = 1;
		for(int i=0;i<e[x].size();i++){
			int a=e[x][i].t,b=e[x][i].w;
			if(dist[a]>y+b){
				dist[a]=y+b;
				heap.push({a,dist[a]});
			}
		} 
	}
}
int main(){
	cin >> n >> m >> s;
	for(int i=0;i<m;i++){
		int u,v,m;
		cin >> u >> v >> m;
		e[u].push_back(edge(u,v,m));
	}
	dijkstra();
	for(int i=1;i<=n;i++){
		cout << dist[i] << " ";
	} 
	return 0;
}

2023/11/17 11:02
加载中...