結果

問題 No.1473 おでぶなおばけさん
ユーザー TomorrowNextTomorrowNext
提出日時 2021-04-09 22:51:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 2,211 bytes
コンパイル時間 1,989 ms
コンパイル使用メモリ 192,824 KB
実行使用メモリ 32,092 KB
最終ジャッジ日時 2023-09-07 12:29:09
合計ジャッジ時間 11,519 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 244 ms
30,104 KB
testcase_03 AC 194 ms
24,428 KB
testcase_04 AC 121 ms
18,244 KB
testcase_05 AC 40 ms
8,068 KB
testcase_06 AC 228 ms
24,932 KB
testcase_07 AC 237 ms
32,080 KB
testcase_08 AC 256 ms
32,092 KB
testcase_09 AC 242 ms
31,844 KB
testcase_10 AC 174 ms
9,688 KB
testcase_11 AC 147 ms
7,944 KB
testcase_12 AC 183 ms
10,404 KB
testcase_13 AC 54 ms
4,376 KB
testcase_14 AC 41 ms
4,380 KB
testcase_15 AC 75 ms
4,376 KB
testcase_16 AC 122 ms
12,636 KB
testcase_17 AC 9 ms
4,380 KB
testcase_18 AC 14 ms
4,592 KB
testcase_19 AC 127 ms
12,912 KB
testcase_20 AC 170 ms
21,672 KB
testcase_21 AC 223 ms
18,896 KB
testcase_22 AC 222 ms
28,128 KB
testcase_23 AC 174 ms
24,568 KB
testcase_24 AC 178 ms
24,064 KB
testcase_25 AC 243 ms
27,580 KB
testcase_26 AC 248 ms
28,184 KB
testcase_27 AC 85 ms
12,596 KB
testcase_28 AC 236 ms
31,304 KB
testcase_29 AC 196 ms
18,228 KB
testcase_30 AC 231 ms
20,308 KB
testcase_31 AC 254 ms
31,152 KB
testcase_32 AC 217 ms
25,004 KB
testcase_33 AC 179 ms
21,704 KB
testcase_34 AC 76 ms
13,672 KB
testcase_35 AC 91 ms
12,600 KB
testcase_36 AC 169 ms
20,896 KB
testcase_37 AC 174 ms
23,264 KB
testcase_38 AC 26 ms
7,152 KB
testcase_39 AC 122 ms
12,824 KB
testcase_40 AC 124 ms
12,880 KB
testcase_41 AC 62 ms
4,376 KB
testcase_42 AC 64 ms
4,380 KB
testcase_43 AC 161 ms
23,920 KB
testcase_44 AC 162 ms
23,976 KB
testcase_45 AC 171 ms
23,980 KB
testcase_46 AC 117 ms
19,752 KB
testcase_47 AC 142 ms
23,364 KB
testcase_48 AC 131 ms
22,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;
using ll = long long;

const int INF = 1 << 30;

void Main() {
    int n, m;
    cin >> n >> m;
    vector<map<int, int>> graph(n, map<int, int>());
    for (int i = 0; i < m; ++i) {
        int s, t, d;
        cin >> s >> t >> d;
        --s;
        --t;
        if (graph[s].count(t) == 0) {
            graph[s].insert(make_pair(t, d));
            graph[t].insert(make_pair(s, d));
        }
        else {
            graph[s][t] = max(graph[s][t], d);
            graph[t][s] = max(graph[t][s], d);
        }
    }

    typedef pair<int, int> weight_curr;
    priority_queue<weight_curr, vector<weight_curr>> q;
    vector<int> w(n, -1);
    int start = 0;
    q.push(make_pair(INF, start));
    w[start] = INF;
    while (!q.empty()) {
        int weight = q.top().first;
        int curr = q.top().second;
        q.pop();
        if (w[curr] > weight) {
            continue;
        }
        for (auto edge : graph[curr]) {
            int to = edge.first;
            int wei = edge.second;
            if (w[to] < min(w[curr], wei)) {
                w[to] = min(w[curr], wei);
                q.push(make_pair(w[to], to));
            }
        }
    }
    int maxWeight = w[n - 1];

    vector<set<int>> allowed(n, set<int>());
    for (int i = 0; i < n; ++i) {
        for (auto e : graph[i]) {
            if (e.second >= maxWeight) {
                allowed[i].insert(e.first);
            }
        }
    }

    typedef pair<int, int> dist_curr;
    priority_queue<dist_curr, vector<dist_curr>, greater<dist_curr>> aq;
    vector<int> d(n, INF);
    aq.push(make_pair(0, start));
    d[start] = 0;
    while (!aq.empty()) {
        int dist = aq.top().first;
        int curr = aq.top().second;
        aq.pop();
        if (d[curr] < dist) {
            continue;
        }
        for (auto to : allowed[curr]) {
            if (d[to] > d[curr] + 1) {
                d[to] = d[curr] + 1;
                aq.push(make_pair(d[to], to));
            }
        }
    }
    int minPath = d[n - 1];
    cout << maxWeight << " " << minPath << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}
0