求助!
  • 板块灌水区
  • 楼主chrispang
  • 当前回复5
  • 已保存回复5
  • 发布时间2024/9/8 14:42
  • 上次更新2024/9/8 17:50:41
查看原帖
求助!
786127
chrispang楼主2024/9/8 14:42

这段代码为什么会CE!

#include <bits/stdc++.h>
#define int long long
using namespace std;

struct rate{
	int to, w;
};

struct node {
	int id, value;
};

bool operator<(node x, node y) {
	return x.value > y.value;
}

vector<rate>linker[10010];
int dis[10010];
bool vis[10010];
void Dijkstra(int n, int m, int s) {
	priority_queue<node>q;
	for (int i = 1; i <= m; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		linker[u].push_back({v, w});
	}
	for (int i = 1; i <= n; i++)
		dis[i] = 1e10;
	dis[s] = 0ll;
	q.push({s, 0ll});
	for (int cnt = 1; cnt <= n; cnt++)
		node temp = q.top();
		q.pop();
		if(vis[temp.id]) continue; 
		int id = temp.id;
		int val = temp.value;
		vis[id] = 1;
		dis[id] = min(val, dis[id]);
		for (int i = 0; i < linker[id].size(); i++)
			q.push({linker[id][i].to, val + linker[id][i].w});
	}
	for (int i = 1; i <= n; i++)
		if(dis[i] == 1e10) cout << -1 << " ";
		else cout << dis[i] << " ";
}

int n, m, s;
signed main() {
	cin >> n >> m >> s;
	Dijkstra(n, m, s);
	return 0;
}
2024/9/8 14:42
加载中...