結果
問題 | No.1301 Strange Graph Shortest Path |
ユーザー | trineutron |
提出日時 | 2020-11-27 22:56:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,086 bytes |
コンパイル時間 | 2,643 ms |
コンパイル使用メモリ | 218,060 KB |
実行使用メモリ | 13,184 KB |
最終ジャッジ日時 | 2024-07-26 20:11:20 |
合計ジャッジ時間 | 11,716 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | WA | - |
testcase_03 | AC | 178 ms
9,420 KB |
testcase_04 | AC | 251 ms
12,544 KB |
testcase_05 | AC | 201 ms
10,520 KB |
testcase_06 | AC | 225 ms
11,520 KB |
testcase_07 | AC | 224 ms
10,976 KB |
testcase_08 | AC | 183 ms
9,432 KB |
testcase_09 | AC | 216 ms
11,264 KB |
testcase_10 | WA | - |
testcase_11 | AC | 237 ms
11,392 KB |
testcase_12 | AC | 243 ms
11,648 KB |
testcase_13 | AC | 234 ms
10,568 KB |
testcase_14 | AC | 221 ms
10,752 KB |
testcase_15 | AC | 213 ms
10,840 KB |
testcase_16 | AC | 263 ms
12,800 KB |
testcase_17 | AC | 233 ms
11,036 KB |
testcase_18 | AC | 203 ms
10,524 KB |
testcase_19 | AC | 232 ms
11,648 KB |
testcase_20 | AC | 233 ms
11,904 KB |
testcase_21 | AC | 225 ms
11,008 KB |
testcase_22 | AC | 239 ms
12,416 KB |
testcase_23 | AC | 219 ms
10,744 KB |
testcase_24 | AC | 227 ms
12,160 KB |
testcase_25 | AC | 245 ms
11,904 KB |
testcase_26 | AC | 221 ms
11,144 KB |
testcase_27 | AC | 231 ms
11,008 KB |
testcase_28 | AC | 192 ms
9,716 KB |
testcase_29 | WA | - |
testcase_30 | AC | 239 ms
11,776 KB |
testcase_31 | AC | 253 ms
12,120 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | AC | 204 ms
11,144 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using point = pair<int64_t, int>; using edge = int; using graph = vector<vector<edge>>; int main() { constexpr int64_t inf = 1e18; int n, m; cin >> n >> m; vector<int64_t> u(m), v(m), c(m), d(m), distance(n, inf); graph to(n); for (int 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)) { int 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); int current = n - 1; while (current) { for (auto prev : to.at(current)) { int 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 (int 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)) { int 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; }