結果
問題 | No.1301 Strange Graph Shortest Path |
ユーザー | m_tsubasa |
提出日時 | 2020-11-27 22:15:49 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,361 bytes |
コンパイル時間 | 3,556 ms |
コンパイル使用メモリ | 216,604 KB |
実行使用メモリ | 39,072 KB |
最終ジャッジ日時 | 2023-10-09 21:18:48 |
合計ジャッジ時間 | 18,205 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,352 KB |
testcase_01 | AC | 2 ms
4,352 KB |
testcase_02 | WA | - |
testcase_03 | AC | 363 ms
27,752 KB |
testcase_04 | AC | 421 ms
37,944 KB |
testcase_05 | AC | 416 ms
29,648 KB |
testcase_06 | AC | 378 ms
34,608 KB |
testcase_07 | AC | 387 ms
32,272 KB |
testcase_08 | AC | 360 ms
28,020 KB |
testcase_09 | AC | 358 ms
33,288 KB |
testcase_10 | WA | - |
testcase_11 | AC | 393 ms
34,752 KB |
testcase_12 | AC | 400 ms
35,536 KB |
testcase_13 | AC | 414 ms
32,184 KB |
testcase_14 | AC | 361 ms
32,464 KB |
testcase_15 | AC | 371 ms
31,832 KB |
testcase_16 | AC | 419 ms
38,552 KB |
testcase_17 | AC | 415 ms
33,600 KB |
testcase_18 | AC | 380 ms
31,004 KB |
testcase_19 | AC | 383 ms
34,996 KB |
testcase_20 | AC | 373 ms
35,604 KB |
testcase_21 | AC | 409 ms
33,224 KB |
testcase_22 | AC | 389 ms
36,756 KB |
testcase_23 | AC | 415 ms
32,656 KB |
testcase_24 | AC | 380 ms
35,640 KB |
testcase_25 | AC | 413 ms
36,812 KB |
testcase_26 | AC | 390 ms
33,324 KB |
testcase_27 | AC | 396 ms
34,408 KB |
testcase_28 | AC | 399 ms
29,480 KB |
testcase_29 | WA | - |
testcase_30 | AC | 414 ms
36,008 KB |
testcase_31 | AC | 417 ms
36,972 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | AC | 449 ms
34,464 KB |
ソースコード
#include <bits/stdc++.h> #define inf (long long)(1e17) using namespace std; using P = pair<long long, long long>; int n, m; vector<map<int, long long>> g, g2; priority_queue<P, vector<P>, greater<P>> pq; long long solve(); int main() { cin >> n >> m; g.resize(n); g2.resize(n); for (int i = 0; i < m; ++i) { int x, y, c, d; cin >> x >> y >> c >> d; --x, --y; g[x][y] = g[y][x] = c; g2[x][y] = g2[y][x] = d; } cout << solve() << endl; return 0; } long long solve() { long long res = 0; auto dijk = [](vector<map<int, long long>> &g, vector<long long> &dist, vector<long long> &par) { dist.assign(n, inf); par.assign(n, -1); pq.push(P(0, 0)); dist[0] = 0; while (pq.size()) { auto [d, now] = pq.top(); pq.pop(); if (d != dist[now]) continue; for (auto [to, cost] : g[now]) if (d + cost < dist[to]) { dist[to] = d + cost; par[to] = now; pq.push(P(dist[to], to)); } } return dist[n - 1]; }; vector<long long> dist, par; res += dijk(g, dist, par); int now = n - 1; while (now != 0) { int to = par[now]; g[to][now] = g[now][to] = -1; now = to; } for (int i = 0; i < n; ++i) for (auto [to, cost] : g[i]) if (cost >= 0) g2[i][to] = cost; return res + dijk(g2, dist, par); }