結果

問題 No.1473 おでぶなおばけさん
ユーザー 蜜蜂
提出日時 2021-04-09 21:44:51
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 274 ms / 2,000 ms
コード長 1,549 bytes
コンパイル時間 4,176 ms
コンパイル使用メモリ 240,992 KB
実行使用メモリ 11,756 KB
最終ジャッジ日時 2024-06-25 04:51:03
合計ジャッジ時間 9,857 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:49:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   49 |       auto[a,b,c]=g[i];
      |           ^
main.cpp:65:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   65 |     auto[a,b,c]=g[i];
      |         ^
main.cpp:78:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   78 |     auto[now,time]=que.top();
      |         ^

ソースコード

diff #

//g++ 4.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;

#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)

using T = tuple<int,int,ll>;
using P = pair<int,int>;

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

  int n,m;
  cin>>n>>m;

  vector<T> g;
  rep(i,0,m){
    int s,t;
    ll d;
    cin>>s>>t>>d;
    s--;t--;
    g.pb({s,t,d});
  }

  ll ng=1e18,ok=0;
  while(ng-ok>1){
    ll check=(ng+ok)/2;
    dsu d(n);
    rep(i,0,m){
      auto[a,b,c]=g[i];
      if(c>=check){
        d.merge(a,b);
      }
    }

    if(d.same(0,n-1)==true){
      ok=check;
    }
    else{
      ng=check;
    }
  }

  vvi graph(n);
  rep(i,0,m){
    auto[a,b,c]=g[i];
    if(c>=ok){
      graph[a].pb(b);
      graph[b].pb(a);
    }
  }

  priority_queue<P,vector<P>,greater<P>> que;
  vi dist(n,1e6);
  que.push({0,0});
  dist[0]=0;

  while(!que.empty()){
    auto[now,time]=que.top();
    que.pop();

    if(time>dist[now])continue;

    for(int next:graph[now]){
      if(dist[next]>dist[now]+1){
        dist[next]=dist[now]+1;
        que.push({next,dist[now]+1});
      }
    }
  }

  cout<<ok<<" "<<dist[n-1]<<endl;
}
0