結果

問題 No.1473 おでぶなおばけさん
ユーザー KKT89KKT89
提出日時 2022-05-01 21:10:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,291 bytes
コンパイル時間 2,347 ms
コンパイル使用メモリ 149,336 KB
実行使用メモリ 10,996 KB
最終ジャッジ日時 2023-09-13 13:59:04
合計ジャッジ時間 8,359 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 58 ms
10,512 KB
testcase_03 AC 45 ms
8,848 KB
testcase_04 AC 31 ms
7,284 KB
testcase_05 AC 12 ms
4,376 KB
testcase_06 AC 49 ms
8,584 KB
testcase_07 AC 61 ms
10,996 KB
testcase_08 AC 62 ms
10,988 KB
testcase_09 AC 61 ms
10,904 KB
testcase_10 AC 36 ms
4,380 KB
testcase_11 AC 35 ms
4,376 KB
testcase_12 AC 36 ms
4,380 KB
testcase_13 AC 23 ms
4,376 KB
testcase_14 AC 17 ms
4,376 KB
testcase_15 AC 31 ms
4,376 KB
testcase_16 AC 34 ms
4,380 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 30 ms
4,920 KB
testcase_20 AC 39 ms
8,248 KB
testcase_21 AC 42 ms
6,488 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 52 ms
8,056 KB
testcase_27 WA -
testcase_28 AC 61 ms
10,760 KB
testcase_29 WA -
testcase_30 AC 47 ms
7,028 KB
testcase_31 AC 51 ms
10,624 KB
testcase_32 AC 39 ms
8,792 KB
testcase_33 AC 34 ms
7,828 KB
testcase_34 AC 20 ms
5,684 KB
testcase_35 AC 20 ms
5,240 KB
testcase_36 WA -
testcase_37 AC 45 ms
8,408 KB
testcase_38 WA -
testcase_39 AC 34 ms
4,376 KB
testcase_40 AC 34 ms
4,380 KB
testcase_41 AC 32 ms
4,384 KB
testcase_42 AC 32 ms
4,376 KB
testcase_43 AC 37 ms
8,004 KB
testcase_44 AC 37 ms
7,972 KB
testcase_45 AC 36 ms
8,008 KB
testcase_46 AC 44 ms
7,828 KB
testcase_47 AC 54 ms
8,940 KB
testcase_48 AC 48 ms
8,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

struct UnionFind{
    vector<int> par,num;
    UnionFind(int n):par(n),num(n,1){
        iota(par.begin(),par.end(),0);  //include<numeric>
    }
    int find(int v){
        return (par[v]==v)?v:(par[v]=find(par[v]));
    }
    void unite(int u,int v){
        u=find(u),v=find(v);
        if(u==v)return;
        if(num[u]<num[v])swap(u,v);
        num[u]+=num[v];
        par[v]=u;
    }
    bool same(int u,int v){
        return find(u) == find(v);
    }
    int size(int v){
        return num[find(v)];
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<pair<int,pair<int,int>>> v(m);
    for(int i=0;i<m;i++){
        cin >> v[i].second.first;
        cin >> v[i].second.second;
        cin >> v[i].first;
        v[i].second.first--;
        v[i].second.second--;
    }
    sort(v.rbegin(), v.rend());
    UnionFind uf(n);
    vector<vector<int>> g(n);
    for(auto p:v){
        int x = p.second.first, y = p.second.second;
        uf.unite(x, y);
        g[x].push_back(y);
        g[y].push_back(x);
        if(uf.same(0,n-1)){
            cout << p.first << " ";
            break;
        }
    }
    vector<int> dp(n,-1);
    dp[0] = 0;
    queue<int> q;
    q.push(0);
    while(q.size()){
        int s = q.front(); q.pop();
        for(int t:g[s]){
            if(dp[t] == -1){
                dp[t] = dp[s]+1;
                q.push(t);
            }
        }
    }
    cout << dp[n-1] << endl;
}

0