結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
oxyshower
|
| 提出日時 | 2020-01-13 22:25:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 508 ms / 4,000 ms |
| コード長 | 1,154 bytes |
| コンパイル時間 | 1,819 ms |
| コンパイル使用メモリ | 183,696 KB |
| 実行使用メモリ | 24,484 KB |
| 最終ジャッジ日時 | 2024-11-23 19:48:47 |
| 合計ジャッジ時間 | 8,135 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
#include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;
struct edge{ int to,cost; };
typedef tuple<int, int, int> P;
signed main(){
int n, m; cin >> n >> m;
vector<vector<edge>> 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});
}
priority_queue<P,vector<P>,greater<P>> que;
vector<vector<int>> dp(2, vector<int>(n, INF));
dp[0][0] = dp[1][0] = 0;
que.push({0, 0, 0}); //{最短距離,頂点}
while( !que.empty() ){
P p = que.top(); que.pop();
int d = get<0>(p), u = get<1>(p), flag = get<2>(p);
if(dp[flag][u] < d) continue;
for(auto e : G[u]){
if(dp[flag][e.to] > dp[flag][u] + e.cost){
dp[flag][e.to] = dp[flag][u] + e.cost;
que.push( {dp[flag][e.to], e.to, flag} );
}
if(flag == 0 && dp[1][e.to] > dp[0][u]){
dp[1][e.to] = dp[0][u];
que.push( {dp[1][e.to], e.to, 1} );
}
}
}
for(int i = 0; i < n; i++){
cout << dp[0][i] + dp[1][i] << endl;
}
return 0;
}
oxyshower