結果

問題 No.1473 おでぶなおばけさん
ユーザー 👑 NachiaNachia
提出日時 2021-04-09 21:51:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,097 bytes
コンパイル時間 2,950 ms
コンパイル使用メモリ 214,088 KB
実行使用メモリ 12,960 KB
最終ジャッジ日時 2023-09-07 10:56:33
合計ジャッジ時間 12,033 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 274 ms
9,896 KB
testcase_03 AC 101 ms
8,340 KB
testcase_04 AC 69 ms
7,128 KB
testcase_05 AC 38 ms
4,384 KB
testcase_06 AC 144 ms
8,260 KB
testcase_07 AC 129 ms
10,552 KB
testcase_08 AC 133 ms
10,352 KB
testcase_09 AC 131 ms
10,368 KB
testcase_10 AC 87 ms
4,420 KB
testcase_11 AC 85 ms
4,412 KB
testcase_12 AC 86 ms
4,384 KB
testcase_13 AC 55 ms
4,384 KB
testcase_14 AC 39 ms
4,380 KB
testcase_15 AC 75 ms
4,376 KB
testcase_16 AC 85 ms
4,380 KB
testcase_17 AC 7 ms
4,376 KB
testcase_18 AC 11 ms
4,376 KB
testcase_19 AC 71 ms
4,940 KB
testcase_20 AC 81 ms
7,864 KB
testcase_21 AC 261 ms
5,924 KB
testcase_22 AC 1,611 ms
8,888 KB
testcase_23 AC 99 ms
8,688 KB
testcase_24 AC 535 ms
7,736 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0; i<(n); i++)

struct DSU{
  vector<int> V;
  DSU(int n=0){ V.resize(n); rep(i,n) V[i]=i; }
  int leader(int a){ return (V[a]==a)?a:(a=leader(V[a])); }
  void merge(int u,int v){ V[leader(u)]=leader(v); }
};

struct Edge{ int u,v,w; };
bool compEdge_w(Edge l, Edge r){ return l.w>r.w; }

int N,M;
vector<Edge> edges;
vector<vector<int>> E;
DSU dsu;
vector<int> D;

int main(){
  cin>>N>>M;
  edges.resize(M);
  rep(i,M){ int u,v,w; cin>>u>>v>>w; u--; v--; edges[i]={u,v,w}; }
  sort(edges.begin(),edges.end(),compEdge_w);
  E.resize(N);
  dsu = DSU(N);
  int W=1001001001;
  for(Edge e:edges){
    dsu.merge(e.u,e.v);
    W = e.w;
    if(dsu.leader(0) == dsu.leader(N-1)) break;
  }
  for(Edge e:edges) if(e.w>=W){
    E[e.u].push_back(e.v);
    E[e.v].push_back(e.u);
  }
  D.assign(N,-1);
  queue<int> Q;
  D[0]=0; Q.push(0);
  while(Q.size()){
    int p=Q.front(); Q.pop();
    for(int e:E[p]) if(D[e]==-1){
      D[e] = D[p]+1;
      Q.push(e);
    }
  }
  cout<<W<<" "<<D[N-1]<<"\n";
  return 0;
}
0