結果

問題 No.1473 おでぶなおばけさん
ユーザー chocoruskchocorusk
提出日時 2021-04-09 21:42:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 2,100 bytes
コンパイル時間 3,438 ms
コンパイル使用メモリ 192,052 KB
実行使用メモリ 10,732 KB
最終ジャッジ日時 2023-09-07 10:33:18
合計ジャッジ時間 10,386 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,012 KB
testcase_01 AC 3 ms
6,012 KB
testcase_02 AC 169 ms
10,124 KB
testcase_03 AC 137 ms
9,248 KB
testcase_04 AC 96 ms
8,472 KB
testcase_05 AC 34 ms
6,540 KB
testcase_06 AC 150 ms
9,192 KB
testcase_07 AC 180 ms
10,468 KB
testcase_08 AC 182 ms
10,732 KB
testcase_09 AC 180 ms
10,452 KB
testcase_10 AC 80 ms
6,932 KB
testcase_11 AC 79 ms
6,984 KB
testcase_12 AC 80 ms
7,488 KB
testcase_13 AC 52 ms
6,528 KB
testcase_14 AC 37 ms
6,648 KB
testcase_15 AC 70 ms
7,236 KB
testcase_16 AC 80 ms
7,136 KB
testcase_17 AC 8 ms
6,140 KB
testcase_18 AC 12 ms
5,932 KB
testcase_19 AC 64 ms
7,604 KB
testcase_20 AC 94 ms
8,940 KB
testcase_21 AC 99 ms
8,164 KB
testcase_22 AC 91 ms
9,616 KB
testcase_23 AC 77 ms
9,252 KB
testcase_24 AC 79 ms
9,280 KB
testcase_25 AC 159 ms
9,632 KB
testcase_26 AC 165 ms
9,808 KB
testcase_27 AC 56 ms
7,708 KB
testcase_28 AC 153 ms
10,332 KB
testcase_29 AC 105 ms
8,248 KB
testcase_30 AC 130 ms
8,560 KB
testcase_31 AC 148 ms
10,392 KB
testcase_32 AC 122 ms
9,112 KB
testcase_33 AC 99 ms
9,040 KB
testcase_34 AC 53 ms
8,220 KB
testcase_35 AC 53 ms
7,052 KB
testcase_36 AC 98 ms
8,652 KB
testcase_37 AC 109 ms
9,344 KB
testcase_38 AC 24 ms
7,292 KB
testcase_39 AC 82 ms
6,916 KB
testcase_40 AC 80 ms
7,216 KB
testcase_41 AC 70 ms
7,304 KB
testcase_42 AC 70 ms
7,584 KB
testcase_43 AC 95 ms
9,132 KB
testcase_44 AC 95 ms
8,888 KB
testcase_45 AC 94 ms
9,060 KB
testcase_46 AC 133 ms
9,068 KB
testcase_47 AC 163 ms
9,512 KB
testcase_48 AC 143 ms
9,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
struct unionfind{
    vector<int> par, sz;
    unionfind() {}
    unionfind(int n):par(n), sz(n, 1){
        for(int i=0; i<n; i++) par[i]=i;
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    void unite(int x, int y){
        x=find(x); y=find(y);
        if(x==y) return;
        if(sz[x]>sz[y]) swap(x, y);
        par[x]=y;
        sz[y]+=sz[x];
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};
int main()
{
    int n; cin>>n;
    int m; cin>>m;
    int a[100010], b[100010], d[100010];
    for(int i=0; i<m; i++){
        cin>>a[i]>>b[i]>>d[i];
        a[i]--; b[i]--;
    }
    int l=0, r=1e9+7;
    while(r-l>1){
        int mid=(l+r)/2;
        unionfind uf(n);
        for(int i=0; i<m; i++){
            if(d[i]>=mid) uf.unite(a[i], b[i]); 
        }
        if(uf.same(0, n-1)) l=mid;
        else r=mid;
    }
    cout<<l<<" ";
    int e[100010];
    const int INF=1e9+7;
    fill(e, e+n, INF);
    e[0]=0;
    queue<int> que; que.push(0);
    vector<int> g[100010];
    for(int i=0; i<m; i++){
        if(d[i]>=l){
            g[a[i]].push_back(b[i]);
            g[b[i]].push_back(a[i]);
        }
    }
    while(!que.empty()){
        int x=que.front(); que.pop();
        for(auto y:g[x]){
            if(e[y]>e[x]+1){
                e[y]=e[x]+1;
                que.push(y);
            }
        }
    }
    cout<<e[n-1]<<endl;
    return 0;
}
0