結果
問題 | No.1301 Strange Graph Shortest Path |
ユーザー | trineutron |
提出日時 | 2020-11-27 23:14:42 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,122 bytes |
コンパイル時間 | 2,436 ms |
コンパイル使用メモリ | 217,048 KB |
実行使用メモリ | 13,368 KB |
最終ジャッジ日時 | 2024-07-26 20:24:08 |
合計ジャッジ時間 | 10,561 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | WA | - |
testcase_03 | AC | 167 ms
10,360 KB |
testcase_04 | AC | 218 ms
13,056 KB |
testcase_05 | AC | 181 ms
11,688 KB |
testcase_06 | AC | 194 ms
12,032 KB |
testcase_07 | AC | 187 ms
11,848 KB |
testcase_08 | AC | 166 ms
10,404 KB |
testcase_09 | AC | 183 ms
11,776 KB |
testcase_10 | WA | - |
testcase_11 | AC | 201 ms
12,032 KB |
testcase_12 | AC | 200 ms
12,288 KB |
testcase_13 | AC | 190 ms
11,596 KB |
testcase_14 | AC | 176 ms
11,520 KB |
testcase_15 | AC | 180 ms
11,748 KB |
testcase_16 | AC | 216 ms
13,308 KB |
testcase_17 | AC | 201 ms
12,088 KB |
testcase_18 | AC | 180 ms
11,344 KB |
testcase_19 | AC | 193 ms
12,160 KB |
testcase_20 | AC | 195 ms
12,416 KB |
testcase_21 | AC | 194 ms
12,136 KB |
testcase_22 | AC | 192 ms
12,800 KB |
testcase_23 | AC | 192 ms
11,768 KB |
testcase_24 | AC | 198 ms
12,544 KB |
testcase_25 | AC | 210 ms
12,800 KB |
testcase_26 | AC | 195 ms
12,124 KB |
testcase_27 | AC | 199 ms
12,032 KB |
testcase_28 | AC | 180 ms
10,916 KB |
testcase_29 | WA | - |
testcase_30 | AC | 206 ms
12,416 KB |
testcase_31 | AC | 214 ms
12,672 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | AC | 184 ms
12,220 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using point = pair<int64_t, int64_t>; using edge = int64_t; using graph = vector<vector<edge>>; int main() { constexpr int64_t inf = 1e18; int64_t n, m; cin >> n >> m; vector<int64_t> u(m), v(m), c(m), d(m), distance(n, inf); graph to(n); for (int64_t i = 0; i < m; i++) { cin >> u.at(i) >> v.at(i) >> c.at(i) >> d.at(i); u.at(i)--; v.at(i)--; to.at(u.at(i)).push_back(i); to.at(v.at(i)).push_back(i); } priority_queue<point, vector<point>, greater<point>> q; q.emplace(0, 0); while (not q.empty()) { auto [cost, vertex] = q.top(); q.pop(); if (cost >= distance.at(vertex)) continue; distance.at(vertex) = cost; for (auto next : to.at(vertex)) { int64_t v_next = u.at(next) + v.at(next) - vertex; int64_t cost_next = cost + c.at(next); if (cost_next >= distance.at(v_next)) continue; q.emplace(cost_next, v_next); } } vector<bool> passed(m); int64_t current = n - 1; while (current) { for (auto prev : to.at(current)) { int64_t v_prev = u.at(prev) + v.at(prev) - current; if (distance.at(current) == distance.at(v_prev) + c.at(prev)) { current = v_prev; passed.at(prev) = true; break; } } } q.emplace(distance.at(n - 1), n - 1); for (int64_t i = 0; i < n; i++) { distance.at(i) = inf; } while (not q.empty()) { auto [cost, vertex] = q.top(); q.pop(); if (cost >= distance.at(vertex)) continue; distance.at(vertex) = cost; for (auto next : to.at(vertex)) { int64_t v_next = u.at(next) + v.at(next) - vertex; int64_t cost_next = cost + c.at(next); if (passed.at(next)) { cost_next = cost + d.at(next); } if (cost_next >= distance.at(v_next)) continue; q.emplace(cost_next, v_next); } } cout << distance.at(0) << endl; }