結果

問題 No.1301 Strange Graph Shortest Path
ユーザー trineutrontrineutron
提出日時 2020-11-27 22:56:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,086 bytes
コンパイル時間 2,421 ms
コンパイル使用メモリ 215,416 KB
実行使用メモリ 13,112 KB
最終ジャッジ日時 2023-10-09 21:50:04
合計ジャッジ時間 11,224 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 178 ms
9,068 KB
testcase_04 AC 239 ms
12,344 KB
testcase_05 AC 186 ms
10,136 KB
testcase_06 AC 220 ms
11,232 KB
testcase_07 AC 207 ms
10,608 KB
testcase_08 AC 170 ms
9,060 KB
testcase_09 AC 199 ms
11,040 KB
testcase_10 WA -
testcase_11 AC 216 ms
11,080 KB
testcase_12 AC 223 ms
11,452 KB
testcase_13 AC 203 ms
10,200 KB
testcase_14 AC 198 ms
10,460 KB
testcase_15 AC 195 ms
10,760 KB
testcase_16 AC 237 ms
12,428 KB
testcase_17 AC 211 ms
10,604 KB
testcase_18 AC 190 ms
9,964 KB
testcase_19 AC 217 ms
11,548 KB
testcase_20 AC 220 ms
11,756 KB
testcase_21 AC 212 ms
10,596 KB
testcase_22 AC 231 ms
12,388 KB
testcase_23 AC 203 ms
10,440 KB
testcase_24 AC 216 ms
11,764 KB
testcase_25 AC 227 ms
11,656 KB
testcase_26 AC 202 ms
10,904 KB
testcase_27 AC 213 ms
10,960 KB
testcase_28 AC 181 ms
9,284 KB
testcase_29 WA -
testcase_30 AC 224 ms
11,468 KB
testcase_31 AC 224 ms
11,948 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 192 ms
10,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0