結果
問題 |
No.807 umg tours
|
ユーザー |
![]() |
提出日時 | 2019-03-22 23:46:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,071 bytes |
コンパイル時間 | 1,877 ms |
コンパイル使用メモリ | 176,984 KB |
実行使用メモリ | 19,844 KB |
最終ジャッジ日時 | 2024-09-19 07:07:25 |
合計ジャッジ時間 | 7,341 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 WA * 14 |
ソースコード
#include "bits/stdc++.h" using namespace std; using P = pair<long, int>; struct edge {int to; long c;}; void solve() { int n, m; cin >> n >> m; vector<long> dist(n, 1e18), dist2(n, 1e18); dist[0] = dist2[0] = 0; vector<edge> g[n]; while(m--) { int a, b; long c; cin >> a >> b >> c; a--, b--; g[a].push_back({b, c}); g[b].push_back({a, c}); } priority_queue<P, vector<P>, greater<P>> q; q.push({0, 0}); while(!q.empty()) { auto p = q.top(); q.pop(); int v = p.second; long c = p.first; if (dist[v] < c) continue; for (auto np : g[v]) { int nv = np.to; long nc = np.c + dist[v]; long nc2 = np.c + dist2[v]; bool done = 0; if (dist[nv] > nc) { dist[nv] = nc; dist2[nv] = min(dist2[nv], dist[v]); q.push({nc, nv}); done = 1; } if (dist2[nv] > nc2) { dist2[nv] = nc2; if (not done) q.push({nc, nv}); } } } for (int i = 0; i < n; i++) { long ans = dist[i] + dist2[i]; cout << ans << endl; } } int main(void) { solve(); //cout << "yui(*-v・)yui" << endl; return 0; }