結果
問題 | No.807 umg tours |
ユーザー |
|
提出日時 | 2020-03-06 14:48:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 595 ms / 4,000 ms |
コード長 | 1,436 bytes |
コンパイル時間 | 2,312 ms |
コンパイル使用メモリ | 182,480 KB |
実行使用メモリ | 23,476 KB |
最終ジャッジ日時 | 2024-11-23 19:50:38 |
合計ジャッジ時間 | 8,618 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const ll INF=1LL<<60; int main(){ int n,m;cin >> n >> m; vector<vector<pair<int,int>>> g(n); for(int i=0;i<m;i++){ int a,b,c;cin >> a >> b >> c; a--,b--; g[a].push_back({b,c}); g[b].push_back({a,c}); } vector<vector<ll>> d(n,vector<ll>(2,INF)); d[0][0]=0; priority_queue<pair<pair<ll,int>,int>,vector<pair<pair<ll,int>,int>>,greater<pair<pair<ll,int>,int>>> pq; pq.push({{0,0},0}); while(!pq.empty()){ ll u=pq.top().first.first; int v=pq.top().first.second,w=pq.top().second; pq.pop(); if(u>d[v][w]){ continue; } for(auto x:g[v]){ if(d[x.first][w]>d[v][w]+x.second){ d[x.first][w]=d[v][w]+x.second; pq.push({{d[x.first][w],x.first},w}); } if(!w){ if(d[x.first][1]>d[v][0]){ d[x.first][1]=d[v][0]; pq.push({{d[x.first][1],x.first},1}); } } } } for(int i=0;i<n;i++){ if(i){ cout << d[i][0]+d[i][1] << endl; } else{ cout << 0 << endl; } } }