結果

問題 No.1601 With Animals into Institute
ユーザー merom686merom686
提出日時 2021-07-10 14:08:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 233 ms / 3,000 ms
コード長 1,686 bytes
コンパイル時間 2,132 ms
コンパイル使用メモリ 206,464 KB
実行使用メモリ 16,732 KB
最終ジャッジ日時 2023-09-14 19:15:34
合計ジャッジ時間 7,390 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 221 ms
16,544 KB
testcase_07 AC 213 ms
16,580 KB
testcase_08 AC 219 ms
16,684 KB
testcase_09 AC 226 ms
16,668 KB
testcase_10 AC 229 ms
16,644 KB
testcase_11 AC 229 ms
16,528 KB
testcase_12 AC 231 ms
16,732 KB
testcase_13 AC 233 ms
16,580 KB
testcase_14 AC 227 ms
16,612 KB
testcase_15 AC 233 ms
16,640 KB
testcase_16 AC 232 ms
16,644 KB
testcase_17 AC 229 ms
16,508 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct Graph {
    static constexpr ll INF = 1LL << 60;
    struct VertexQ {
        bool operator<(const VertexQ &o) const {
            return c > o.c; // 逆
        }
        int i;
        ll c;
    };
    struct Vertex { int n; ll c; };
    struct Edge { int i, n, c; };
    Graph(int n, int m) : v(n, { -1, INF }), e(m), n(n), m(0) {}
    void add_edge(int a, int b, int c) {
        e[m] = { b, v[a].n, c };
        v[a].n = m;
        m++;
    }
    void dijkstra(int i) {
        for (int i = 0; i < n; i++) v[i].c = INF;
        priority_queue<VertexQ> q;
        q.push({ i, v[i].c = 0 });
        while (!q.empty()) {
            auto p = q.top(); q.pop();
            if (p.c > v[p.i].c) continue;
            for (int j = v[p.i].n; j >= 0; j = e[j].n) {
                Edge &o = e[j];
                ll c = p.c + o.c;
                if (c < v[o.i].c) q.push({ o.i, v[o.i].c = c });
            }
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    Graph g(n * 2, m * 4);
    for (int i = 0; i < m; i++) {
        int a, b, c, x;
        cin >> a >> b >> c >> x;
        a--; b--;

        if (x == 0) {
            g.add_edge(a, b, c);
            g.add_edge(b, a, c);
        } else {
            g.add_edge(n + a, b, c);
            g.add_edge(n + b, a, c);
        }
        g.add_edge(n + a, n + b, c);
        g.add_edge(n + b, n + a, c);
    }
    g.dijkstra(n + (n - 1));

    for (int i = 0; i < n - 1; i++) {
        cout << g.v[i].c << '\n';
    }

    return 0;
}
0