結果
問題 | No.807 umg tours |
ユーザー |
|
提出日時 | 2019-03-22 22:00:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 485 ms / 4,000 ms |
コード長 | 1,113 bytes |
コンパイル時間 | 830 ms |
コンパイル使用メモリ | 84,188 KB |
実行使用メモリ | 18,484 KB |
最終ジャッジ日時 | 2024-11-23 18:58:52 |
合計ジャッジ時間 | 7,023 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include<iostream> #include<vector> #include<queue> using namespace std; typedef long long ll; const ll INF = 1ll<<60; int main(){ int n, m; cin >> n >> m; vector<pair<int,int>> v[n]; int a, b, c; for(int i = 0; i < m; i++){ cin >> a >> b >> c; a--, b--; v[a].push_back({b, c}); v[b].push_back({a, c}); } vector<vector<ll>> d(2, vector<ll>(n, INF)); priority_queue<pair<ll, pair<int, int>>> pq; pq.push({-0, {0, 0}}); while(!pq.empty()){ auto p = pq.top(); pq.pop(); ll cost = -p.first; int pos = p.second.first, used = p.second.second; if(d[used][pos] <= cost) continue; d[used][pos] = cost; for(pair<int,int> path : v[pos]){ ll ncost = cost + path.second; int next = path.first; if(d[used][next] > ncost) pq.push({-ncost, {next, used}}); if(used == 0 && d[1][next] > cost) pq.push({-cost, {next, 1}}); } } cout << 0 << endl; for(int i = 1; i < n; i++){ cout << d[1][i]+d[0][i] << endl; } return 0; }