結果

問題 No.1473 おでぶなおばけさん
ユーザー snow39snow39
提出日時 2021-04-09 21:51:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,271 bytes
コンパイル時間 1,586 ms
コンパイル使用メモリ 125,592 KB
実行使用メモリ 11,932 KB
最終ジャッジ日時 2023-09-07 10:56:21
合計ジャッジ時間 6,128 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 72 ms
10,876 KB
testcase_03 AC 56 ms
9,356 KB
testcase_04 AC 38 ms
7,592 KB
testcase_05 AC 13 ms
4,484 KB
testcase_06 AC 59 ms
9,292 KB
testcase_07 AC 83 ms
11,860 KB
testcase_08 AC 80 ms
11,660 KB
testcase_09 AC 78 ms
11,932 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 41 ms
4,680 KB
testcase_13 AC 27 ms
4,760 KB
testcase_14 AC 19 ms
4,384 KB
testcase_15 AC 36 ms
4,764 KB
testcase_16 AC 40 ms
4,804 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 6 ms
4,384 KB
testcase_19 AC 35 ms
5,184 KB
testcase_20 AC 47 ms
8,564 KB
testcase_21 WA -
testcase_22 AC 59 ms
10,760 KB
testcase_23 AC 55 ms
10,168 KB
testcase_24 AC 49 ms
9,568 KB
testcase_25 AC 64 ms
10,344 KB
testcase_26 AC 62 ms
10,352 KB
testcase_27 AC 21 ms
5,008 KB
testcase_28 AC 70 ms
11,332 KB
testcase_29 AC 45 ms
7,176 KB
testcase_30 AC 51 ms
7,528 KB
testcase_31 WA -
testcase_32 AC 45 ms
9,292 KB
testcase_33 AC 40 ms
8,348 KB
testcase_34 WA -
testcase_35 AC 21 ms
5,216 KB
testcase_36 AC 41 ms
7,304 KB
testcase_37 AC 51 ms
9,664 KB
testcase_38 AC 10 ms
4,380 KB
testcase_39 AC 40 ms
4,740 KB
testcase_40 AC 41 ms
4,680 KB
testcase_41 AC 38 ms
4,760 KB
testcase_42 AC 37 ms
4,744 KB
testcase_43 AC 40 ms
8,588 KB
testcase_44 AC 40 ms
8,500 KB
testcase_45 AC 40 ms
8,492 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
権限があれば一括ダウンロードができます

ソースコード

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);
  vector<vector<int>> g(N);
  int lastCost=-1;
  rep(i,N){
    int now=ord[i];
    auto [a,b,c]=edges[now];

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

  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