結果

問題 No.1473 おでぶなおばけさん
ユーザー 👑 NachiaNachia
提出日時 2021-04-09 21:52:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,119 bytes
コンパイル時間 2,317 ms
コンパイル使用メモリ 213,520 KB
実行使用メモリ 10,536 KB
最終ジャッジ日時 2023-09-07 10:59:09
合計ジャッジ時間 10,792 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 211 ms
9,968 KB
testcase_03 AC 49 ms
8,364 KB
testcase_04 AC 37 ms
7,012 KB
testcase_05 AC 27 ms
4,388 KB
testcase_06 AC 89 ms
8,316 KB
testcase_07 AC 71 ms
10,484 KB
testcase_08 AC 73 ms
10,428 KB
testcase_09 AC 72 ms
10,536 KB
testcase_10 AC 39 ms
4,420 KB
testcase_11 AC 38 ms
4,624 KB
testcase_12 AC 39 ms
4,404 KB
testcase_13 AC 25 ms
4,380 KB
testcase_14 AC 18 ms
4,376 KB
testcase_15 AC 33 ms
4,380 KB
testcase_16 AC 35 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 39 ms
4,976 KB
testcase_20 AC 44 ms
7,720 KB
testcase_21 AC 215 ms
6,008 KB
testcase_22 AC 1,548 ms
8,956 KB
testcase_23 AC 69 ms
8,572 KB
testcase_24 AC 500 ms
7,908 KB
testcase_25 TLE -
testcase_26 AC 986 ms
8,420 KB
testcase_27 AC 33 ms
4,616 KB
testcase_28 AC 61 ms
10,484 KB
testcase_29 AC 38 ms
6,460 KB
testcase_30 AC 44 ms
7,056 KB
testcase_31 AC 783 ms
10,212 KB
testcase_32 AC 57 ms
8,408 KB
testcase_33 AC 288 ms
7,640 KB
testcase_34 AC 333 ms
5,668 KB
testcase_35 AC 44 ms
5,096 KB
testcase_36 AC 986 ms
6,260 KB
testcase_37 AC 116 ms
8,048 KB
testcase_38 AC 10 ms
4,376 KB
testcase_39 AC 37 ms
4,452 KB
testcase_40 AC 37 ms
4,448 KB
testcase_41 AC 35 ms
4,500 KB
testcase_42 AC 34 ms
4,380 KB
testcase_43 AC 39 ms
7,832 KB
testcase_44 AC 38 ms
7,852 KB
testcase_45 AC 40 ms
7,848 KB
testcase_46 AC 47 ms
7,472 KB
testcase_47 AC 56 ms
8,632 KB
testcase_48 AC 50 ms
8,412 KB
権限があれば一括ダウンロードができます

ソースコード

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(){
  scanf("%d%d",&N,&M);
  edges.resize(M);
  rep(i,M){ int u,v,w; scanf("%d%d%d",&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