結果

問題 No.1601 With Animals into Institute
ユーザー 鴨志田卓鴨志田卓
提出日時 2023-07-20 17:44:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 376 ms / 3,000 ms
コード長 1,183 bytes
コンパイル時間 2,411 ms
コンパイル使用メモリ 209,192 KB
実行使用メモリ 30,988 KB
最終ジャッジ日時 2023-10-20 18:14:43
合計ジャッジ時間 12,277 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,820 KB
testcase_01 AC 5 ms
9,820 KB
testcase_02 AC 4 ms
9,820 KB
testcase_03 AC 8 ms
10,380 KB
testcase_04 AC 8 ms
10,388 KB
testcase_05 AC 8 ms
10,396 KB
testcase_06 AC 367 ms
30,956 KB
testcase_07 AC 363 ms
30,920 KB
testcase_08 AC 361 ms
30,932 KB
testcase_09 AC 368 ms
30,988 KB
testcase_10 AC 372 ms
30,944 KB
testcase_11 AC 372 ms
30,944 KB
testcase_12 AC 372 ms
30,940 KB
testcase_13 AC 363 ms
30,976 KB
testcase_14 AC 367 ms
30,932 KB
testcase_15 AC 376 ms
30,940 KB
testcase_16 AC 368 ms
30,980 KB
testcase_17 AC 374 ms
30,904 KB
testcase_18 AC 8 ms
10,444 KB
testcase_19 AC 8 ms
10,448 KB
testcase_20 AC 9 ms
10,448 KB
testcase_21 AC 9 ms
10,452 KB
testcase_22 AC 8 ms
10,464 KB
testcase_23 AC 8 ms
10,448 KB
testcase_24 AC 8 ms
10,448 KB
testcase_25 AC 8 ms
10,452 KB
testcase_26 AC 8 ms
10,456 KB
testcase_27 AC 5 ms
9,820 KB
testcase_28 AC 5 ms
9,820 KB
testcase_29 AC 5 ms
9,820 KB
testcase_30 AC 5 ms
9,824 KB
testcase_31 AC 5 ms
9,824 KB
testcase_32 AC 5 ms
9,824 KB
testcase_33 AC 5 ms
9,824 KB
testcase_34 AC 5 ms
9,824 KB
testcase_35 AC 5 ms
9,824 KB
testcase_36 AC 5 ms
9,824 KB
testcase_37 AC 5 ms
9,824 KB
testcase_38 AC 5 ms
9,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int N = 1e5 + 10;

using edge = pair<long long, int>;

int n, m;
vector<edge> g[N * 2];

long long dis[N * 2];

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

    cin >> n >> m;
    for(int i = 1, u, v, w, b; i <= m; i ++) {
        cin >> u >> v >> w >> b;
        g[u].push_back({w, v});
        g[v].push_back({w, u});
        
        g[N + u].push_back({w, N + v});
        g[N + v].push_back({w, N + u});
        
        if(b) {
            g[u].push_back({w, N + v});
            g[v].push_back({w, N + u});
        
            g[N + u].push_back({w, v});
            g[N + v].push_back({w, u});
        }
    }

    memset(dis, 0x3f, sizeof dis);
    dis[N + n] = 0;
    priority_queue<edge, vector<edge>, greater<edge> > pq;
    pq.push({0, N + n});
    while(pq.size()) {
        auto [d, u] = pq.top();
        pq.pop();

        if(dis[u] < d) continue;

        for(auto [w, v] : g[u]) {
            if(dis[v] > dis[u] + w) {
                dis[v] = dis[u] + w;
                pq.push({dis[v], v});
            }
        }
    }

    for(int i = 1; i < n; i ++)
        cout << dis[i] << "\n";

}
0