結果

問題 No.1473 おでぶなおばけさん
ユーザー KKT89KKT89
提出日時 2022-05-01 21:12:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,343 bytes
コンパイル時間 4,366 ms
コンパイル使用メモリ 149,204 KB
実行使用メモリ 11,024 KB
最終ジャッジ日時 2023-09-13 14:01:28
合計ジャッジ時間 7,113 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 58 ms
10,516 KB
testcase_03 AC 45 ms
8,804 KB
testcase_04 AC 32 ms
7,220 KB
testcase_05 AC 13 ms
4,380 KB
testcase_06 AC 49 ms
8,688 KB
testcase_07 AC 62 ms
10,896 KB
testcase_08 AC 67 ms
11,000 KB
testcase_09 AC 60 ms
10,976 KB
testcase_10 AC 35 ms
4,396 KB
testcase_11 AC 35 ms
4,408 KB
testcase_12 AC 35 ms
4,480 KB
testcase_13 AC 23 ms
4,376 KB
testcase_14 AC 17 ms
4,380 KB
testcase_15 AC 31 ms
4,380 KB
testcase_16 AC 34 ms
4,380 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 WA -
testcase_20 AC 39 ms
8,084 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 50 ms
10,716 KB
testcase_32 AC 38 ms
8,876 KB
testcase_33 AC 34 ms
7,856 KB
testcase_34 AC 20 ms
5,696 KB
testcase_35 AC 20 ms
5,104 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 34 ms
4,384 KB
testcase_40 AC 35 ms
4,400 KB
testcase_41 AC 32 ms
4,412 KB
testcase_42 AC 33 ms
4,376 KB
testcase_43 AC 37 ms
7,900 KB
testcase_44 AC 37 ms
7,920 KB
testcase_45 AC 36 ms
7,948 KB
testcase_46 AC 43 ms
7,956 KB
testcase_47 AC 52 ms
8,936 KB
testcase_48 AC 47 ms
8,668 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);
    int u = -1;
    for(auto p:v){
        if(p.first < u)break;
        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 << " ";
            u = p.first;
        }
    }
    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