社区讨论
这题开INT64_MAX过不了,INT32_MAX能过,数据不行啊
P3371【模板】单源最短路径(弱化版)参与者 7已保存回复 9
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 8 条
- 当前快照
- 1 份
- 快照标识符
- @logp0a76
- 此快照首次捕获于
- 2023/11/02 12:34 2 年前
- 此快照最后确认于
- 2023/11/02 16:45 2 年前
CPP
using i64 = long long;
i64 n, m, s;
struct point {
i64 v, w;
bool operator<(const point &other) const { return w > other.w; }
};
vector<vector<point>> graph;
vector<i64> dijkstra(const i64 s = 1) {
vector<i64> map(n + 1, INT32_MAX); //改成INT64_MAX却过不了第三个点,第三个点有个答案就正好是INT32_MAX
vector<bool> vis(n + 1, false);
priority_queue<point> q;
map[s] = 0;
q.emplace(s, 0);
while (not q.empty()) {
point t = q.top();
q.pop();
if (vis[t.v])
continue;
vis[t.v] = true;
for (auto &&i : graph[t.v])
if (map[t.v] + i.w < map[i.v]) {
map[i.v] = map[t.v] + i.w;
q.emplace(i.v, map[i.v]);
}
}
map.erase(map.begin());
return map;
}
回复
共 9 条回复,欢迎继续交流。
正在加载回复...