結果

問題 No.1473 おでぶなおばけさん
ユーザー beetbeet
提出日時 2021-04-09 21:23:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 1,845 bytes
コンパイル時間 2,639 ms
コンパイル使用メモリ 220,100 KB
実行使用メモリ 16,524 KB
最終ジャッジ日時 2023-09-07 09:42:21
合計ジャッジ時間 7,336 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 82 ms
15,160 KB
testcase_03 AC 63 ms
12,500 KB
testcase_04 AC 42 ms
10,300 KB
testcase_05 AC 15 ms
5,212 KB
testcase_06 AC 61 ms
12,332 KB
testcase_07 AC 87 ms
16,472 KB
testcase_08 AC 90 ms
16,524 KB
testcase_09 AC 86 ms
16,408 KB
testcase_10 AC 37 ms
4,680 KB
testcase_11 AC 37 ms
4,832 KB
testcase_12 AC 36 ms
4,960 KB
testcase_13 AC 24 ms
4,832 KB
testcase_14 AC 18 ms
4,380 KB
testcase_15 AC 32 ms
4,820 KB
testcase_16 AC 36 ms
4,740 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 33 ms
5,676 KB
testcase_20 AC 51 ms
11,488 KB
testcase_21 AC 48 ms
7,816 KB
testcase_22 AC 68 ms
13,132 KB
testcase_23 AC 60 ms
12,932 KB
testcase_24 AC 55 ms
11,612 KB
testcase_25 AC 70 ms
12,632 KB
testcase_26 AC 70 ms
12,392 KB
testcase_27 AC 25 ms
5,456 KB
testcase_28 AC 81 ms
16,228 KB
testcase_29 AC 47 ms
8,436 KB
testcase_30 AC 56 ms
9,236 KB
testcase_31 AC 84 ms
15,704 KB
testcase_32 AC 55 ms
12,336 KB
testcase_33 AC 46 ms
11,068 KB
testcase_34 AC 25 ms
7,388 KB
testcase_35 AC 23 ms
6,112 KB
testcase_36 AC 48 ms
7,920 KB
testcase_37 AC 57 ms
11,984 KB
testcase_38 AC 11 ms
4,380 KB
testcase_39 AC 36 ms
4,760 KB
testcase_40 AC 36 ms
4,668 KB
testcase_41 AC 34 ms
4,836 KB
testcase_42 AC 34 ms
4,764 KB
testcase_43 AC 44 ms
10,944 KB
testcase_44 AC 44 ms
11,084 KB
testcase_45 AC 44 ms
11,056 KB
testcase_46 AC 56 ms
11,080 KB
testcase_47 AC 65 ms
12,544 KB
testcase_48 AC 60 ms
12,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}


vector<int> bfs(int s,vector< vector<int> > G){
  int n=G.size();
  vector<int> dp(n,-1);
  queue<int> que;
  dp[s]=0;
  que.emplace(s);
  while(!que.empty()){
    int v=que.front();que.pop();
    for(int u:G[v]){
      if(~dp[u]) continue;
      dp[u]=dp[v]+1;
      que.emplace(u);
    }
  }
  return dp;
}


struct UnionFind{
  int num;
  vector<int> rs,ps;
  UnionFind(int n):num(n),rs(n,1),ps(n,0){
    iota(ps.begin(),ps.end(),0);
  }
  int find(int x){
    return (x==ps[x]?x:ps[x]=find(ps[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(rs[x]<rs[y]) swap(x,y);
    rs[x]+=rs[y];
    ps[y]=x;
    num--;
  }
  int size(int x){
    return rs[find(x)];
  }
  int count() const{
    return num;
  }
};

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n,m;
  cin>>n>>m;

  using T = tuple<int, int, int>;
  vector<T> es;
  for(int i=0;i<m;i++){
    int s,t,d;
    cin>>s>>t>>d;
    s--;t--;
    es.emplace_back(d,s,t);
  }
  sort(es.rbegin(),es.rend());

  UnionFind uf(n);
  int w=-1;
  for(auto[d,s,t]:es){
    uf.unite(s,t);
    if(uf.same(0,n-1)){
      w=d;
      break;
    }
  }
  vector<vector<int>> G(n);
  for(auto[d,s,t]:es){
    if(d<w) break;
    G[s].emplace_back(t);
    G[t].emplace_back(s);
  }
  cout<<w<<' '<<bfs(0,G)[n-1]<<endl;
  return 0;
}
0