結果

問題 No.1473 おでぶなおばけさん
ユーザー shun2741shun2741
提出日時 2021-04-09 22:12:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 2,814 bytes
コンパイル時間 4,559 ms
コンパイル使用メモリ 265,988 KB
実行使用メモリ 11,432 KB
最終ジャッジ日時 2023-09-07 11:35:29
合計ジャッジ時間 11,455 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 165 ms
10,760 KB
testcase_03 AC 135 ms
9,256 KB
testcase_04 AC 86 ms
7,456 KB
testcase_05 AC 34 ms
4,524 KB
testcase_06 AC 150 ms
9,132 KB
testcase_07 AC 169 ms
11,360 KB
testcase_08 AC 170 ms
11,340 KB
testcase_09 AC 172 ms
11,432 KB
testcase_10 AC 87 ms
5,400 KB
testcase_11 AC 86 ms
5,572 KB
testcase_12 AC 87 ms
5,428 KB
testcase_13 AC 54 ms
4,612 KB
testcase_14 AC 39 ms
4,380 KB
testcase_15 AC 74 ms
5,308 KB
testcase_16 AC 85 ms
5,396 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 69 ms
5,808 KB
testcase_20 AC 89 ms
8,568 KB
testcase_21 AC 104 ms
7,136 KB
testcase_22 AC 91 ms
9,816 KB
testcase_23 AC 74 ms
9,104 KB
testcase_24 AC 76 ms
8,612 KB
testcase_25 AC 135 ms
9,604 KB
testcase_26 AC 145 ms
9,332 KB
testcase_27 AC 54 ms
5,168 KB
testcase_28 AC 148 ms
11,048 KB
testcase_29 AC 114 ms
7,184 KB
testcase_30 AC 130 ms
7,964 KB
testcase_31 AC 139 ms
10,976 KB
testcase_32 AC 113 ms
9,256 KB
testcase_33 AC 96 ms
8,124 KB
testcase_34 AC 52 ms
5,892 KB
testcase_35 AC 55 ms
5,692 KB
testcase_36 AC 99 ms
7,176 KB
testcase_37 AC 102 ms
8,724 KB
testcase_38 AC 23 ms
4,376 KB
testcase_39 AC 86 ms
5,376 KB
testcase_40 AC 88 ms
5,444 KB
testcase_41 AC 78 ms
5,400 KB
testcase_42 AC 75 ms
5,492 KB
testcase_43 AC 100 ms
8,628 KB
testcase_44 AC 100 ms
8,836 KB
testcase_45 AC 100 ms
8,744 KB
testcase_46 AC 136 ms
8,268 KB
testcase_47 AC 168 ms
9,364 KB
testcase_48 AC 146 ms
9,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// デバッグ表示
#define dump(x) cout << #x << ":" << (x) << endl;

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// modint
using mint = modint1000000007;
// using mint = modint998244353;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第2引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// コンビネーションを計算する関数
ll pow(ll N, ll k) {
    ll res = 1;
    for (ll i = 0; i < k; ++i) res *= N;
    return res;
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

ll N, M;
vector<ll> S;
vector<ll> T;
vector<ll> D;

bool check(ll u){
    dsu A(N);

    REP(i, M){
        ll s = S[i];
        ll t = T[i];
        ll d = D[i];
        s--;
        t--;

        if(u <= d) A.merge(s, t);
    }
    if(A.same(0, N-1)) return true;
    else return false;
}

int main()
{
    cout << fixed << setprecision(15);
    cin >> N >> M;

    
    S.resize(M);
    T.resize(M);
    D.resize(M);

    REP(i, M){
        cin >> S[i] >> T[i] >> D[i];
    }

    ll left = 0;
    ll right = LINF;

    while(right-left > 1) { // ループ継続条件
        ll middle = ((right - left) / 2) + left;

        //大丈夫なときはもう少し大きい値を見る
        if(check(middle)){ // 範囲右寄せ,左寄せ条件
            left = middle; // 左寄せ手法
        } else {
            right = middle; // 右寄せ手法
        }
    }

    // leftが最大の体重
    // dump(left);

    Graph G(N);

    REP(i, M){
        ll s = S[i];
        ll t = T[i];
        ll d = D[i];

        s--;
        t--;

        if(left <= d){
            G[s].push_back(t);
            G[t].push_back(s);
        }
    }

    vector<int> dist(N, -1);
    queue<int> que;

    dist[0] = 0;
    que.push(0);

    while(!que.empty()){
        int p;
        p = que.front();
        que.pop();

        for(int next :G[p]){
            // もし次のノードが訪問済みなら処理を飛ばす
            if(dist[next] != -1) continue;

            dist[next] = dist[p] + 1;
            que.push(next);
        }
    }

    // REP(i, N){
    //     cout << "i:" << i << " dist[i]:" << dist[i] << endl;
    // }
    cout << left << " " << dist[N-1] << endl;
    return 0;
}
0