結果

問題 No.1473 おでぶなおばけさん
ユーザー siro53siro53
提出日時 2021-04-09 22:28:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 2,706 bytes
コンパイル時間 2,747 ms
コンパイル使用メモリ 208,308 KB
実行使用メモリ 9,484 KB
最終ジャッジ日時 2023-09-07 11:57:02
合計ジャッジ時間 8,538 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 109 ms
9,228 KB
testcase_03 AC 89 ms
8,412 KB
testcase_04 AC 71 ms
6,516 KB
testcase_05 AC 28 ms
4,380 KB
testcase_06 AC 122 ms
8,588 KB
testcase_07 AC 108 ms
9,484 KB
testcase_08 AC 157 ms
9,380 KB
testcase_09 AC 99 ms
9,440 KB
testcase_10 AC 35 ms
5,356 KB
testcase_11 AC 38 ms
6,268 KB
testcase_12 AC 37 ms
5,768 KB
testcase_13 AC 23 ms
4,756 KB
testcase_14 AC 17 ms
4,384 KB
testcase_15 AC 31 ms
5,492 KB
testcase_16 AC 32 ms
4,824 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 41 ms
5,628 KB
testcase_20 AC 66 ms
7,760 KB
testcase_21 AC 80 ms
6,724 KB
testcase_22 AC 59 ms
8,460 KB
testcase_23 AC 44 ms
7,940 KB
testcase_24 AC 46 ms
7,632 KB
testcase_25 AC 152 ms
8,256 KB
testcase_26 AC 153 ms
8,280 KB
testcase_27 AC 34 ms
4,736 KB
testcase_28 AC 133 ms
9,324 KB
testcase_29 AC 76 ms
7,032 KB
testcase_30 AC 99 ms
7,764 KB
testcase_31 AC 90 ms
9,284 KB
testcase_32 AC 88 ms
8,712 KB
testcase_33 AC 69 ms
7,736 KB
testcase_34 AC 34 ms
5,348 KB
testcase_35 AC 34 ms
5,416 KB
testcase_36 AC 61 ms
6,252 KB
testcase_37 AC 80 ms
7,652 KB
testcase_38 AC 13 ms
4,376 KB
testcase_39 AC 33 ms
4,944 KB
testcase_40 AC 32 ms
4,884 KB
testcase_41 AC 31 ms
4,948 KB
testcase_42 AC 31 ms
5,096 KB
testcase_43 AC 38 ms
7,012 KB
testcase_44 AC 38 ms
6,888 KB
testcase_45 AC 39 ms
6,880 KB
testcase_46 AC 64 ms
7,212 KB
testcase_47 AC 85 ms
8,136 KB
testcase_48 AC 77 ms
7,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define FOR(i, a, b) for(int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

void Case(int i) { cout << "Case #" << i << ": "; }
#pragma endregion Macros

struct E{
    int to;
    int w;
};

int N, M;
vector<vector<E>> G;

int check(int W) {
    vector<int> dp(N, INF);
    dp[0] = 0;
    queue<int> que;
    que.emplace(0);

    while(!que.empty()) {
        int u = que.front(); que.pop();
        for(auto [v, d] : G[u]) {
            if(W > d) continue;
            if(dp[v] == INF) {
                dp[v] = dp[u] + 1;
                que.emplace(v);
            }
        }
    }

    return dp[N-1];
}

int main() {
    cin >> N >> M;
    G.resize(N);
    REP(_, M) {
        int s, t, w;
        cin >> s >> t >> w;
        s--; t--;
        G[s].push_back(E{t, w});
        G[t].push_back(E{s, w});
    }

    int ok = 0, ng = int(1e9) + 10;
    int ans = INF;
    while(ng - ok > 1) {
        int mid = (ok + ng) / 2;
        int tmp = check(mid);
        if(tmp == INF) {
            ng = mid;
        }else{
            ok = mid;
            ans = tmp;
        }
    }
    assert(ans != INF);
    cout << ok << " " << ans << endl;
}
0