結果

問題 No.1601 With Animals into Institute
ユーザー firiexpfiriexp
提出日時 2021-07-10 14:07:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 386 ms / 3,000 ms
コード長 1,826 bytes
コンパイル時間 1,156 ms
コンパイル使用メモリ 114,748 KB
実行使用メモリ 31,056 KB
最終ジャッジ日時 2023-09-14 19:14:16
合計ジャッジ時間 8,314 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 5 ms
4,384 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 380 ms
30,852 KB
testcase_07 AC 384 ms
30,728 KB
testcase_08 AC 374 ms
30,996 KB
testcase_09 AC 381 ms
31,056 KB
testcase_10 AC 386 ms
30,740 KB
testcase_11 AC 382 ms
30,764 KB
testcase_12 AC 385 ms
30,776 KB
testcase_13 AC 385 ms
30,780 KB
testcase_14 AC 384 ms
30,732 KB
testcase_15 AC 383 ms
30,796 KB
testcase_16 AC 386 ms
30,740 KB
testcase_17 AC 386 ms
30,712 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 5 ms
4,384 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 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 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <typename T>
struct edge {
    int from, to; T cost;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template <typename T>
vector<T> dijkstra(int s,vector<vector<edge<T>>> &G){
    auto n = G.size();
    vector<T> d(n, INF<T>);
    priority_queue<pair<T, int>,vector<pair<T, int>>,greater<>> Q;
    d[s] = 0;
    Q.emplace(0, s);
    while(!Q.empty()){
        T cost; int i;
        tie(cost, i) = Q.top(); Q.pop();
        if(d[i] < cost) continue;
        for (auto &&e : G[i]) {
            auto cost2 = cost + e.cost;
            if(d[e.to] <= cost2) continue;
            d[e.to] = cost2;
            Q.emplace(d[e.to], e.to);
        }
    }
    return d;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<edge<ll>>> G(2*n);
    for (int i = 0; i < m; ++i) {
        int a, b, c, x;
        scanf("%d %d %d %d", &a, &b, &c, &x);
        a--; b--;
        if(x){
            G[a].emplace_back(b+n, c);
            G[b].emplace_back(a+n, c);
            G[a+n].emplace_back(b+n, c);
            G[b+n].emplace_back(a+n, c);
        }else {
            G[a].emplace_back(b, c);
            G[b].emplace_back(a, c);
            G[a+n].emplace_back(b+n, c);
            G[b+n].emplace_back(a+n, c);
        }
    }
    auto d = dijkstra(n-1, G);
    for (int i = 0; i < n-1; ++i) {
        printf("%lld\n", d[i+n]);
    }
    return 0;
}
0