結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
mencotton
|
| 提出日時 | 2020-11-02 21:46:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,509 bytes |
| コンパイル時間 | 715 ms |
| コンパイル使用メモリ | 81,692 KB |
| 実行使用メモリ | 27,144 KB |
| 最終ジャッジ日時 | 2024-07-22 08:05:48 |
| 合計ジャッジ時間 | 6,893 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 WA * 4 |
ソースコード
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct edge {
int to;
int cost;
};
struct status {
int cost;
int v;
bool operator<(const status &rhs) const { return cost < rhs.cost; };
bool operator>(const status &rhs) const { return cost > rhs.cost; };
};
const int INF = (1 << 30) - 1;
vector<int> dijkstra(int s, int n, vector<vector<edge>> &graph) {
priority_queue<status, vector<status>, greater<>> que;
vector<int> dis(n, INF);
dis[s] = 0;
que.push({0, s});
while (!que.empty()) {
status now = que.top();
que.pop();
if (dis[now.v] < now.cost)continue;
for (auto next:graph[now.v]) {
if (dis[next.to] > dis[now.v] + next.cost) {
dis[next.to] = dis[now.v] + next.cost;
que.push({dis[next.to], next.to});
}
}
}
return dis;
}
int main() {
int n, m;
cin >> n >> m;
vector<vector<edge>> graph(n * 2);
for (int i = 0; i < m; i++) {
int u, v, cost;
cin >> u >> v >> cost, u--, v--;
graph[u].push_back({v, cost}), graph[v].push_back({u, cost});
graph[u].push_back({v + n, 0}), graph[v].push_back({u + n, 0});
graph[u + n].push_back({v + n, cost}), graph[v + n].push_back({u + n, cost});
}
vector<int> dis = dijkstra(0, n * 2, graph);
cout << 0 << endl;
for (int i = 1; i < n; i++) cout << dis[i] + dis[i + n] << "\n";
cout << flush;
return 0;
}
mencotton