結果

問題 No.1473 おでぶなおばけさん
ユーザー 👑 NachiaNachia
提出日時 2021-04-09 21:54:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,124 bytes
コンパイル時間 2,492 ms
コンパイル使用メモリ 215,320 KB
実行使用メモリ 10,476 KB
最終ジャッジ日時 2023-09-07 11:01:35
合計ジャッジ時間 6,604 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 63 ms
9,940 KB
testcase_03 AC 49 ms
8,844 KB
testcase_04 AC 34 ms
7,040 KB
testcase_05 AC 13 ms
4,380 KB
testcase_06 AC 55 ms
8,280 KB
testcase_07 AC 69 ms
10,476 KB
testcase_08 AC 69 ms
10,408 KB
testcase_09 AC 66 ms
10,432 KB
testcase_10 AC 39 ms
4,412 KB
testcase_11 AC 39 ms
4,404 KB
testcase_12 AC 38 ms
4,408 KB
testcase_13 AC 25 ms
4,380 KB
testcase_14 AC 19 ms
4,380 KB
testcase_15 AC 35 ms
4,376 KB
testcase_16 AC 37 ms
4,376 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 31 ms
4,884 KB
testcase_20 AC 41 ms
7,792 KB
testcase_21 AC 44 ms
6,060 KB
testcase_22 AC 49 ms
8,848 KB
testcase_23 AC 42 ms
8,656 KB
testcase_24 AC 40 ms
8,092 KB
testcase_25 AC 54 ms
8,628 KB
testcase_26 AC 56 ms
8,456 KB
testcase_27 AC 21 ms
4,620 KB
testcase_28 AC 60 ms
10,368 KB
testcase_29 AC 38 ms
6,340 KB
testcase_30 AC 45 ms
6,796 KB
testcase_31 AC 59 ms
10,164 KB
testcase_32 AC 45 ms
8,328 KB
testcase_33 AC 39 ms
7,632 KB
testcase_34 AC 22 ms
5,420 KB
testcase_35 AC 22 ms
4,888 KB
testcase_36 AC 39 ms
6,328 KB
testcase_37 AC 43 ms
8,184 KB
testcase_38 AC 10 ms
4,376 KB
testcase_39 AC 38 ms
4,380 KB
testcase_40 AC 38 ms
4,420 KB
testcase_41 AC 36 ms
4,376 KB
testcase_42 AC 36 ms
4,376 KB
testcase_43 AC 41 ms
7,864 KB
testcase_44 AC 41 ms
7,736 KB
testcase_45 AC 41 ms
7,848 KB
testcase_46 AC 48 ms
7,664 KB
testcase_47 AC 58 ms
8,692 KB
testcase_48 AC 51 ms
8,372 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:(V[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);
    }
  }
  printf("%d %d\n",W,D[N-1]);
  return 0;
}
0