結果
問題 | No.807 umg tours |
ユーザー |
![]() |
提出日時 | 2019-03-22 22:11:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,978 bytes |
コンパイル時間 | 940 ms |
コンパイル使用メモリ | 113,964 KB |
実行使用メモリ | 19,484 KB |
最終ジャッジ日時 | 2024-09-19 05:43:45 |
合計ジャッジ時間 | 3,487 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 8 WA * 18 |
ソースコード
#include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <string> #include <vector> #include <random> #include <bitset> #include <queue> #include <cmath> #include <stack> #include <set> #include <map> #define int long long using namespace std; const int INF = 1LL << 18; struct edge { int to; int cost; }; typedef pair <int, int> P; typedef pair <int, P> PP; int V, E; vector <edge> G[100005]; int d[2][100005]; // 0: チケットを使わない最短距離 // 1: チケットを1回使った時の最短距離 void dijkstra() { priority_queue<PP, vector<PP>, greater<PP>> q; fill(d[0], d[1]+V, INF); d[0][0] = d[1][0] = 0LL; q.push(PP(0LL, P(0, 0))); while (!q.empty()) { PP p = q.top(); q.pop(); int cost = p.first; int cur = p.second.first; int used = p.second.second; if (d[used][cur] < cost) continue; for (edge e : G[cur]) { if (used == 1) { if (d[1][e.to] > d[1][cur] + e.cost) { d[1][e.to] = d[1][cur] + e.cost; q.push(PP(d[1][e.to], P(e.to, 1))); } } else { if (d[0][e.to] > d[0][cur] + e.cost) { d[0][e.to] = d[0][cur] + e.cost; q.push(PP(d[0][e.to], P(e.to, 0))); } if (d[1][e.to] > d[0][cur]) { d[1][e.to] = d[0][cur]; q.push(PP(d[1][e.to], P(e.to, 1))); } } } } } signed main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> V >> E; for (int i = 0; i < E; i++) { int a, b; int c; cin >> a >> b >> c; a--; b--; G[a].push_back((edge){b, c}); G[b].push_back((edge){a, c}); } dijkstra(); for (int i = 0; i < V; i++) { cout << d[0][i] + d[1][i] << "\n"; } return 0; }