結果

問題 No.1601 With Animals into Institute
ユーザー nawawannawawan
提出日時 2021-07-10 14:23:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 533 ms / 3,000 ms
コード長 1,717 bytes
コンパイル時間 2,643 ms
コンパイル使用メモリ 178,756 KB
実行使用メモリ 34,220 KB
最終ジャッジ日時 2023-09-14 19:24:31
合計ジャッジ時間 11,665 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 8 ms
4,384 KB
testcase_04 AC 8 ms
4,380 KB
testcase_05 AC 8 ms
4,376 KB
testcase_06 AC 527 ms
33,872 KB
testcase_07 AC 530 ms
33,860 KB
testcase_08 AC 524 ms
34,144 KB
testcase_09 AC 528 ms
34,064 KB
testcase_10 AC 523 ms
34,220 KB
testcase_11 AC 522 ms
34,040 KB
testcase_12 AC 533 ms
33,920 KB
testcase_13 AC 525 ms
34,052 KB
testcase_14 AC 527 ms
33,888 KB
testcase_15 AC 526 ms
33,872 KB
testcase_16 AC 523 ms
33,992 KB
testcase_17 AC 527 ms
34,016 KB
testcase_18 AC 9 ms
4,384 KB
testcase_19 AC 9 ms
4,376 KB
testcase_20 AC 8 ms
4,380 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 8 ms
4,376 KB
testcase_23 AC 9 ms
4,380 KB
testcase_24 AC 9 ms
4,380 KB
testcase_25 AC 9 ms
4,376 KB
testcase_26 AC 9 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:38:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   38 |         auto [dis, id] = q.top();
      |              ^
main.cpp:54:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   54 |         auto [dis, id] = q.top();
      |              ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
struct edge{
    int to;
    long long cost;
};
typedef pair<long long, int> P;
int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<edge>> G(N + 2 * M);
    vector<int> mon;
    for(int i = 0; i < M; i++){
        int a, b, x;
        long long c;
        cin >> a >> b >> c >> x;
        a--;
        b--;
        if(x == 1) {
            G[a].push_back({i + N, c});
            G[i + N].push_back({b, 0});
            G[b].push_back({i + M + N, c});
            G[i + M + N].push_back({a, 0});
            mon.push_back(i + N);
            mon.push_back(i + M + N);
        }
        else{
            G[a].push_back({b, c});
            G[b].push_back({a, c});
        }
    }
    long long INF = 10000000000000000;
    vector<long long> d(N + 2 * M, INF);
    priority_queue<P, vector<P>, greater<P>> q;
    d[N - 1] = 0;
    q.push({0, N - 1});
    while(!q.empty()){
        auto [dis, id] = q.top();
        q.pop();
        if(d[id] < dis) continue;
        for(edge e : G[id]){
            if(d[e.to] > e.cost + dis){
                d[e.to] = e.cost + dis;
                q.push({d[e.to], e.to});
            }
        }
    }
    vector<long long> ans(N + 2 * M, INF);
    for(int i = 0; i < (int)mon.size(); i++){
        q.push({d[mon[i]], mon[i]});
        ans[mon[i]] = d[mon[i]];
    }
    while(!q.empty()){
        auto [dis, id] = q.top();
        q.pop();
        if(ans[id] < dis) continue;
        for(edge e : G[id]){
            if(ans[e.to] > e.cost + dis){
                ans[e.to] = e.cost + dis;
                q.push({ans[e.to], e.to});
            }
        }
    }
    for(int i  = 0; i < N - 1; i++) cout << ans[i] << endl;
}
0