結果
| 問題 |
No.807 umg tours
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-21 13:59:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 653 ms / 4,000 ms |
| コード長 | 1,453 bytes |
| コンパイル時間 | 1,802 ms |
| コンパイル使用メモリ | 180,444 KB |
| 実行使用メモリ | 45,512 KB |
| 最終ジャッジ日時 | 2024-11-23 19:58:52 |
| 合計ジャッジ時間 | 9,908 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long ;
using P = pair<ll,int> ;
const int INF = 1e9;
const int MOD = 1000000007;
int n = 100005,m = 200005;
vector<vector<P>> graph(2*n,vector<P>());
vector<ll> dijkstra(ll start){
vector<ll> shortest(2*n+10);
vector<bool> visited(2*n+10,false);
priority_queue<P,vector<P>,greater<P>> pq;
pq.push(make_pair(0,start));
while (!pq.empty()){
P now = pq.top();
pq.pop();
ll cost;int node;
tie(cost,node) = now;
if(visited[node]){
continue;
}else{
shortest[node] = cost;
visited[node] = true;
for(P next:graph[node]){
ll next_cost;int next_node;
tie(next_cost,next_node) = next;
pq.push(make_pair(cost+next_cost,next_node));
}
}
}
return shortest;
}
int main(){
cin >> n >> m;
rep(i,m){
int a,b;
ll c;
cin >> a >> b >> c;
--a;--b;
graph[a].push_back(P(c,b));
graph[a].push_back(P(0,b+n));
graph[b].push_back(P(c,a));
graph[b].push_back(P(0,a+n));
graph[a+n].push_back(P(c,b+n));
graph[b+n].push_back(P(c,a+n));
}
vector<ll> dis = dijkstra(0);
rep(i,n){
if(i==0) cout << 0 << '\n';
else cout << dis[i] + dis[i+n] << '\n';
}
return 0;
}