結果

問題 No.1601 With Animals into Institute
ユーザー ぷらぷら
提出日時 2021-07-10 14:08:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 580 ms / 3,000 ms
コード長 1,227 bytes
コンパイル時間 2,162 ms
コンパイル使用メモリ 211,564 KB
実行使用メモリ 20,156 KB
最終ジャッジ日時 2023-09-14 19:15:00
合計ジャッジ時間 11,467 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 8 ms
4,376 KB
testcase_05 AC 9 ms
4,376 KB
testcase_06 AC 566 ms
19,868 KB
testcase_07 AC 566 ms
20,012 KB
testcase_08 AC 552 ms
20,044 KB
testcase_09 AC 547 ms
19,992 KB
testcase_10 AC 559 ms
19,980 KB
testcase_11 AC 557 ms
19,976 KB
testcase_12 AC 569 ms
20,156 KB
testcase_13 AC 575 ms
19,992 KB
testcase_14 AC 572 ms
19,852 KB
testcase_15 AC 579 ms
20,072 KB
testcase_16 AC 580 ms
19,888 KB
testcase_17 AC 580 ms
19,892 KB
testcase_18 AC 8 ms
4,380 KB
testcase_19 AC 8 ms
4,380 KB
testcase_20 AC 8 ms
4,376 KB
testcase_21 AC 8 ms
4,376 KB
testcase_22 AC 8 ms
4,380 KB
testcase_23 AC 8 ms
4,376 KB
testcase_24 AC 8 ms
4,380 KB
testcase_25 AC 9 ms
4,380 KB
testcase_26 AC 8 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr long long inf = 1001001001001001001;

bool chmin(long long &x,long long y) {
    if(x > y) {
        x = y;
        return true;
    }
    return false;
}

int main() {
    int N,M;
    cin >> N >> M;
    vector<vector<array<int,3>>>road(N);
    for(int i = 0; i < M; i++) {
        int A,B,C,X;
        cin >> A >> B >> C >> X;
        A--;
        B--;
        road[A].push_back({B,C,X});
        road[B].push_back({A,C,X});
    }
    vector<vector<long long>>dist(N,vector<long long>(2,inf));
    dist[N-1][0] = 0;
    priority_queue<array<long long,3>,vector<array<long long,3>>,greater<array<long long,3>>>que;
    que.push({0,N-1,0});
    while (!que.empty()) {
        array<long long,3> x = que.top();
        que.pop();
        if(dist[x[1]][x[2]] != x[0]) {
            continue;
        }
        for(int i = 0; i < road[x[1]].size(); i++) {
            int nxt = road[x[1]][i][0];
            if(chmin(dist[nxt][x[2]|road[x[1]][i][2]],x[0]+road[x[1]][i][1])) {
                que.push({dist[nxt][x[2]|road[x[1]][i][2]],nxt,x[2]|road[x[1]][i][2]});
            }
        }
    }
    for(int i = 0; i < N-1; i++) {
        cout << dist[i][1] << endl;
    }
}
0