結果
問題 |
No.807 umg tours
|
ユーザー |
![]() |
提出日時 | 2019-04-20 16:15:44 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 345 ms / 4,000 ms |
コード長 | 1,269 bytes |
コンパイル時間 | 1,856 ms |
コンパイル使用メモリ | 174,888 KB |
実行使用メモリ | 42,132 KB |
最終ジャッジ日時 | 2024-11-23 19:27:23 |
合計ジャッジ時間 | 6,593 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long lint; typedef pair<lint, int> P; struct edge{int to; lint cost;}; const int MAX_N = (int)2e5 + 5; const lint INF = (lint)1e16; int N, M; lint dist[MAX_N]; vector<edge> G[MAX_N]; void dijkstra(int s){ priority_queue<P, vector<P>, greater<P>> pq; for(int i=0;i<2*N;i++) dist[i] = INF; dist[0] = dist[N] = 0; pq.push({0, 0}); while(!pq.empty()){ P p = pq.top(); pq.pop(); if(dist[p.second]<p.first) continue; int u = p.second; for(auto v : G[u]){ lint x = dist[v.to], y = dist[u]+v.cost; if(dist[v.to]>dist[u]+v.cost){ dist[v.to] = dist[u] + v.cost; pq.push({dist[v.to], v.to}); } } } } int main(){ scanf("%d %d", &N, &M); for(int i=0;i<M;i++){ int a, b, c; scanf("%d %d %d", &a, &b, &c); G[a-1].push_back(edge{b-1, c}); G[a-1].push_back(edge{b-1+N, 0}); G[b-1].push_back(edge{a-1, c}); G[b-1].push_back(edge{a-1+N, 0}); G[a-1+N].push_back(edge{b-1+N, c}); G[b-1+N].push_back(edge{a-1+N, c}); } dijkstra(0); for(int i=0;i<N;i++){ printf("%lld\n", dist[i]+dist[N+i]); } return 0; }