結果

問題 No.1473 おでぶなおばけさん
ユーザー saxofone111saxofone111
提出日時 2021-04-14 21:12:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 767 ms / 2,000 ms
コード長 1,919 bytes
コンパイル時間 2,250 ms
コンパイル使用メモリ 211,476 KB
実行使用メモリ 12,984 KB
最終ジャッジ日時 2023-09-13 10:28:40
合計ジャッジ時間 17,441 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 521 ms
12,764 KB
testcase_03 AC 217 ms
11,428 KB
testcase_04 AC 359 ms
8,372 KB
testcase_05 AC 90 ms
4,864 KB
testcase_06 AC 475 ms
11,176 KB
testcase_07 AC 431 ms
12,980 KB
testcase_08 AC 767 ms
12,984 KB
testcase_09 AC 316 ms
12,888 KB
testcase_10 AC 91 ms
7,472 KB
testcase_11 AC 94 ms
8,856 KB
testcase_12 AC 92 ms
8,056 KB
testcase_13 AC 54 ms
6,124 KB
testcase_14 AC 39 ms
5,236 KB
testcase_15 AC 77 ms
7,812 KB
testcase_16 AC 84 ms
6,736 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 105 ms
7,576 KB
testcase_20 AC 151 ms
10,212 KB
testcase_21 AC 209 ms
9,624 KB
testcase_22 AC 156 ms
11,180 KB
testcase_23 AC 132 ms
9,900 KB
testcase_24 AC 121 ms
9,756 KB
testcase_25 AC 469 ms
11,224 KB
testcase_26 AC 473 ms
11,276 KB
testcase_27 AC 83 ms
6,128 KB
testcase_28 AC 608 ms
11,964 KB
testcase_29 AC 283 ms
9,796 KB
testcase_30 AC 322 ms
11,044 KB
testcase_31 AC 312 ms
12,628 KB
testcase_32 AC 294 ms
11,440 KB
testcase_33 AC 218 ms
10,272 KB
testcase_34 AC 93 ms
6,612 KB
testcase_35 AC 101 ms
6,728 KB
testcase_36 AC 192 ms
8,704 KB
testcase_37 AC 398 ms
10,180 KB
testcase_38 AC 40 ms
4,688 KB
testcase_39 AC 86 ms
6,732 KB
testcase_40 AC 85 ms
6,676 KB
testcase_41 AC 81 ms
6,336 KB
testcase_42 AC 80 ms
6,344 KB
testcase_43 AC 154 ms
10,292 KB
testcase_44 AC 154 ms
10,292 KB
testcase_45 AC 154 ms
10,348 KB
testcase_46 AC 147 ms
9,388 KB
testcase_47 AC 185 ms
10,728 KB
testcase_48 AC 196 ms
10,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll W;

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(W>ip.c)continue;
          if(d[ip.x]<=d[x]+1){
            continue;
          }else{
            d[ip.x]= d[x]+1;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};



/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, M;
  cin >> N >> M;
  dijkstra dijk(N);
  rep(i, M){
    ll a, b, c;
    cin >> a >> b >> c;
    a--;b--;
    dijk.add_edge(a, b, c);
    dijk.add_edge(b, a, c);
  }

  ll ok = 0;
  ll ng = 1e18;
  while(abs(ok-ng)>1){
    W =(ok+ng)/2;
    dijk.run(0);
    if(dijk.d[N-1]<1e18){
      ok = W;
    }else{
      ng = W;
    }
  }

  W = ok;
  dijk.run(0);
  cout << W << " " << dijk.d.back()<<endl;
  
  
  return 0;
}
0