結果

問題 No.1473 おでぶなおばけさん
ユーザー snow39snow39
提出日時 2021-04-09 21:55:36
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 2,210 bytes
コンパイル時間 1,574 ms
コンパイル使用メモリ 124,776 KB
実行使用メモリ 11,800 KB
最終ジャッジ日時 2023-09-07 11:04:16
合計ジャッジ時間 5,931 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 72 ms
11,000 KB
testcase_03 AC 55 ms
9,424 KB
testcase_04 AC 38 ms
7,596 KB
testcase_05 AC 13 ms
4,480 KB
testcase_06 AC 58 ms
9,352 KB
testcase_07 AC 79 ms
11,672 KB
testcase_08 AC 78 ms
11,788 KB
testcase_09 AC 77 ms
11,800 KB
testcase_10 AC 40 ms
4,688 KB
testcase_11 AC 40 ms
5,020 KB
testcase_12 AC 40 ms
4,688 KB
testcase_13 AC 26 ms
4,748 KB
testcase_14 AC 19 ms
4,376 KB
testcase_15 AC 36 ms
4,700 KB
testcase_16 AC 39 ms
4,796 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 6 ms
4,384 KB
testcase_19 AC 34 ms
5,068 KB
testcase_20 AC 48 ms
8,624 KB
testcase_21 AC 49 ms
6,780 KB
testcase_22 AC 49 ms
9,888 KB
testcase_23 AC 42 ms
9,292 KB
testcase_24 AC 41 ms
8,772 KB
testcase_25 AC 54 ms
9,804 KB
testcase_26 AC 55 ms
9,568 KB
testcase_27 AC 21 ms
4,948 KB
testcase_28 AC 73 ms
11,536 KB
testcase_29 AC 45 ms
7,044 KB
testcase_30 AC 51 ms
7,460 KB
testcase_31 AC 57 ms
11,140 KB
testcase_32 AC 44 ms
9,300 KB
testcase_33 AC 39 ms
8,320 KB
testcase_34 AC 22 ms
5,864 KB
testcase_35 AC 21 ms
5,272 KB
testcase_36 AC 39 ms
6,644 KB
testcase_37 AC 45 ms
9,144 KB
testcase_38 AC 9 ms
4,376 KB
testcase_39 AC 40 ms
4,696 KB
testcase_40 AC 40 ms
4,696 KB
testcase_41 AC 37 ms
4,688 KB
testcase_42 AC 38 ms
4,804 KB
testcase_43 AC 40 ms
8,612 KB
testcase_44 AC 40 ms
8,516 KB
testcase_45 AC 40 ms
8,504 KB
testcase_46 AC 53 ms
8,364 KB
testcase_47 AC 65 ms
9,292 KB
testcase_48 AC 59 ms
9,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

class DisjointSet{
public:
  int N;
  vector<int> rank,p;
  vector<int> sz;
 
  DisjointSet(){}
  DisjointSet(int n):N(n),rank(n),p(n),sz(n){
    for(int i=0;i<N;i++) makeSet(i);
  }
 
  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
    sz[x]=1;
  }
 
  bool same(int x,int y){
    return leader(x)==leader(y);
  }
 
  void unite(int x,int y){
    if(same(x,y)) return;
    link(leader(x),leader(y));
  }
 
  void link(int x,int y){
    if(rank[x]>rank[y]) swap(x,y);

    p[x]=y;
    sz[y]+=sz[x];
    if(rank[x]==rank[y]){
      ++rank[y];
    }
  }
 
  int leader(int x){
    if(x!=p[x]) p[x]=leader(p[x]);
    return p[x];
  }
 
  int size(int x){
    return sz[leader(x)];
  }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N,M;
  cin>>N>>M;
  vector<tuple<int,int,int>> edges;
  rep(i,M){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    edges.push_back(mkt(a,b,c));
  }

  vector<int> ord(M,0);
  rep(i,M) ord[i]=i;

  sort(all(ord),[&](int a,int b){
    if(get<2>(edges[a])!=get<2>(edges[b])) return get<2>(edges[a]) > get<2>(edges[b]);
    return a<b;
  });

  DisjointSet us(N);
  int lastCost=-1;
  for(auto i:ord){
    auto [a,b,c]=edges[i];

    us.unite(a,b);
    if(us.same(0,N-1)){
      lastCost=c;
      break;
    }
  }

  vector<vector<int>> g(N);
  for(auto i:ord){
    auto [a,b,c]=edges[i];
    if(c>=lastCost){
      g[a].push_back(b);
      g[b].push_back(a);
    }
  }

  queue<int> Q;
  vector<int> dist(N,MOD);
  dist[0]=0;
  Q.push(0);
  while(!Q.empty()){
    int now=Q.front();
    Q.pop();

    for(auto nex:g[now]){
      if(dist[nex]==MOD){
        dist[nex]=dist[now]+1;
        Q.push(nex);
      }
    }
  }

  cout<<lastCost<<" "<<dist[N-1]<<endl;

  return 0;
}
0