結果

問題 No.1301 Strange Graph Shortest Path
ユーザー Ricky_ponRicky_pon
提出日時 2020-11-27 22:24:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,680 bytes
コンパイル時間 2,394 ms
コンパイル使用メモリ 216,428 KB
実行使用メモリ 19,224 KB
最終ジャッジ日時 2023-10-09 21:25:34
合計ジャッジ時間 7,915 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 85 ms
13,864 KB
testcase_04 AC 150 ms
18,976 KB
testcase_05 AC 86 ms
14,228 KB
testcase_06 AC 127 ms
17,300 KB
testcase_07 AC 113 ms
15,724 KB
testcase_08 AC 91 ms
13,652 KB
testcase_09 AC 118 ms
16,796 KB
testcase_10 WA -
testcase_11 AC 127 ms
17,016 KB
testcase_12 AC 138 ms
17,576 KB
testcase_13 AC 109 ms
15,772 KB
testcase_14 AC 123 ms
15,720 KB
testcase_15 AC 117 ms
15,392 KB
testcase_16 AC 159 ms
18,888 KB
testcase_17 AC 115 ms
16,332 KB
testcase_18 AC 102 ms
14,988 KB
testcase_19 AC 128 ms
17,320 KB
testcase_20 AC 129 ms
17,356 KB
testcase_21 AC 110 ms
16,052 KB
testcase_22 AC 137 ms
18,108 KB
testcase_23 AC 107 ms
15,988 KB
testcase_24 AC 128 ms
17,740 KB
testcase_25 AC 133 ms
18,152 KB
testcase_26 AC 115 ms
16,104 KB
testcase_27 AC 117 ms
16,468 KB
testcase_28 AC 85 ms
14,420 KB
testcase_29 WA -
testcase_30 AC 131 ms
18,048 KB
testcase_31 AC 136 ms
18,360 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 114 ms
17,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

//#include <atcoder/all>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

template <typename T>
struct edge {
    int from, to, id;
    T cost[2];
    edge(int f, int t, T c, T d, int i = 0) : from(f), to(t), id(i) {
        cost[0] = c;
        cost[1] = d;
    }
};

template <typename T>
struct Graph {
    vector<vector<edge<T>>> G;
    int n;

    Graph(int n_) : n(n_) { G.resize(n); }

    void add_edge(int f, int t, T c, T d, int i = 0) {
        G[f].emplace_back(f, t, c, d, i);
    }
};

int used[MAX];

template <typename T>
pair<vector<T>, vector<pii>> dijkstra(Graph<T> &gr, int s) {
    using state = pair<T, int>;
    priority_queue<state, vector<state>, greater<state>> que;
    vector<T> d(gr.n, numeric_limits<T>::max());
    vector<pii> pe(gr.n);
    d[s] = 0;
    que.emplace(0, s);
    while (!que.empty()) {
        state p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (edge<T> &e : gr.G[v]) {
            if (d[e.to] > d[v] + e.cost[used[e.id]]) {
                d[e.to] = d[v] + e.cost[used[e.id]];
                pe[e.to] = {e.id, v};
                que.emplace(d[e.to], e.to);
            }
        }
    }
    return {d, pe};
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    Graph<lint> gr(n);
    rep(i, m) {
        int a, b;
        lint c, d;
        scanf("%d%d%lld%lld", &a, &b, &c, &d);
        --a;
        --b;
        gr.add_edge(a, b, c, d, i);
        gr.add_edge(b, a, c, d, i);
    }

    auto [d, pe] = dijkstra(gr, 0);
    int v = n - 1;
    while (v != 0) {
        used[pe[v].fi] = 1;
        v = pe[v].se;
    }

    auto [d2, pe2] = dijkstra(gr, n - 1);
    printf("%lld\n", d[n - 1] + d2[0]);
}
0