結果
問題 | No.807 umg tours |
ユーザー | veqcc |
提出日時 | 2019-03-22 22:12:30 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 263 ms / 4,000 ms |
コード長 | 1,973 bytes |
コンパイル時間 | 1,398 ms |
コンパイル使用メモリ | 112,384 KB |
実行使用メモリ | 25,920 KB |
最終ジャッジ日時 | 2023-08-15 11:59:28 |
合計ジャッジ時間 | 5,659 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
7,296 KB |
testcase_01 | AC | 5 ms
7,284 KB |
testcase_02 | AC | 4 ms
7,232 KB |
testcase_03 | AC | 5 ms
7,260 KB |
testcase_04 | AC | 4 ms
7,296 KB |
testcase_05 | AC | 5 ms
7,400 KB |
testcase_06 | AC | 5 ms
7,372 KB |
testcase_07 | AC | 5 ms
7,380 KB |
testcase_08 | AC | 5 ms
7,376 KB |
testcase_09 | AC | 5 ms
7,324 KB |
testcase_10 | AC | 5 ms
7,380 KB |
testcase_11 | AC | 135 ms
18,592 KB |
testcase_12 | AC | 139 ms
15,752 KB |
testcase_13 | AC | 193 ms
18,232 KB |
testcase_14 | AC | 76 ms
12,084 KB |
testcase_15 | AC | 56 ms
10,608 KB |
testcase_16 | AC | 196 ms
19,140 KB |
testcase_17 | AC | 263 ms
23,428 KB |
testcase_18 | AC | 258 ms
23,096 KB |
testcase_19 | AC | 256 ms
20,060 KB |
testcase_20 | AC | 134 ms
12,644 KB |
testcase_21 | AC | 140 ms
12,908 KB |
testcase_22 | AC | 50 ms
9,676 KB |
testcase_23 | AC | 37 ms
9,116 KB |
testcase_24 | AC | 99 ms
21,660 KB |
testcase_25 | AC | 260 ms
25,920 KB |
ソースコード
#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 << 60; 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] + 100005, 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, 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; }