結果
問題 | No.807 umg tours |
ユーザー |
|
提出日時 | 2020-05-18 21:27:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 521 ms / 4,000 ms |
コード長 | 1,142 bytes |
コンパイル時間 | 2,199 ms |
コンパイル使用メモリ | 188,304 KB |
実行使用メモリ | 24,472 KB |
最終ジャッジ日時 | 2024-11-23 20:04:20 |
合計ジャッジ時間 | 8,819 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; using lint = long long; lint n, m; typedef tuple<lint, lint, lint> P; struct edge{lint to, cost;}; vector<vector<edge> > G; vector<vector<lint> > dist; const lint INF= 1e18; void dij(int start){ priority_queue<P, vector<P>, greater<P> > que; dist[0][0] = 0; dist[1][0] = 0; que.push(P(0, start, 0)); while(!que.empty()){ P p = que.top(); que.pop(); int d = get<0>(p), u = get<1>(p), flag = get<2>(p); if(dist[flag][u] < d) continue; for(auto e : G[u]){ if(dist[flag][e.to] > dist[flag][u] + e.cost){ dist[flag][e.to] = dist[flag][u] + e.cost; que.push( {dist[flag][e.to], e.to, flag} ); } if(flag == 0 && dist[1][e.to] > dist[0][u]){ dist[1][e.to] = dist[0][u]; que.push( {dist[1][e.to], e.to, 1} ); } } } } signed main(){ cin >> n >> m; G.resize(n); dist.resize(2, vector<lint> (n, INF)); for(int i = 0; i < m; i++){ lint a, b, c; cin >> a >> b >> c; --a; --b; G[a].push_back(edge{b, c}); G[b].push_back(edge{a, c}); } dij(0); for(int i = 0; i < n; i++) cout << dist[0][i] + dist[1][i] << endl; }