Dij 70 分求调,悬关
查看原帖
Dij 70 分求调,悬关
922727
ZhouYuXuanAllen楼主2023/10/27 21:01
#include <bits/stdc++.h>
using namespace std;
struct qwq{
	int num, dis;
	bool operator<(const qwq &b)const{return dis < b.dis;}
};
priority_queue<qwq> q;
vector<int> g[10005], c[10005];
int n, m, s, a, b, x, d[10005];
int main(){
	cin >> n >> m >> s;
	memset(d, 0x3f, sizeof(d)); 
	q.push({s, 0}); d[s] = 0;
	while (m--){
		cin >> a >> b >> x;
		g[a].push_back(b), c[a].push_back(x); 
	} while (!q.empty()){
		qwq tp = q.top(); q.pop();
		for (int i = 0;i < g[tp.num].size();i++){
			int n1 = g[tp.num][i], n2 = c[tp.num][i];
			if (d[n1] > tp.dis + n2) d[n1] = tp.dis + n2, q.push({n1, d[n1]});
		}
	} for (int i = 1;i <= n;i++) cout << (d[i] > 1e9 ? 2147483647 : d[i]) << ' ';
	return 0;
}
2023/10/27 21:01
加载中...