結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-03-22 22:21:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,464 bytes |
| コンパイル時間 | 1,530 ms |
| コンパイル使用メモリ | 169,184 KB |
| 実行使用メモリ | 26,132 KB |
| 最終ジャッジ日時 | 2024-11-23 19:05:52 |
| 合計ジャッジ時間 | 12,799 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 TLE * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, long long> > graph[100010];
typedef pair<long long, pair<int, int> > P;
long long dist[100010][2];
int main(){
int n, m;
cin >> n >> m;
int a, b;
long long c;
for(int i = 0;i < m;i++){
cin >> a >> b >> c;
a--, b--;
graph[a].push_back(make_pair(b, c));
graph[b].push_back(make_pair(a, c));
}
dist[0][1] = 0;
dist[0][0] = 0;
for(int i = 1;i < n;i++){
dist[i][0] = dist[i][1] = LLONG_MAX;
}
priority_queue<P, vector<P>, greater<P> > que;
que.push(make_pair(0, make_pair(0, 1)));
que.push(make_pair(0, make_pair(0, 0)));
while(!que.empty()){
long long cost = que.top().first;
int idx = que.top().second.first;
int tk = que.top().second.second;
que.pop();
for(int i = 0;i < graph[idx].size();i++){
int next = graph[idx][i].first;
long long ncost = graph[idx][i].second;
if(cost + ncost < dist[next][tk]){
dist[next][tk] = cost + ncost;
que.push(make_pair(dist[next][tk], make_pair(next, tk)));
}
if(tk == 1 && cost < dist[next][0]){
dist[next][0] = cost;
que.push(make_pair(cost, make_pair(next, 0)));
}
}
}
for(int i = 0;i < n;i++){
cout << dist[i][1] + dist[i][0] << endl;
}
return 0;
}