結果

問題 No.1473 おでぶなおばけさん
ユーザー yataro800
提出日時 2023-01-10 21:21:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 1,592 bytes
コンパイル時間 3,994 ms
コンパイル使用メモリ 237,160 KB
実行使用メモリ 11,824 KB
最終ジャッジ日時 2024-12-21 12:19:33
合計ジャッジ時間 10,914 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <math.h>

#include <algorithm>
#include <array>
#include <atcoder/all>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using namespace atcoder;

using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<P_ll>> G(n);
  for (int i = 0; i < m; i++) {
    ll s, t, d;
    cin >> s >> t >> d;
    s--;
    t--;
    G[s].push_back({t, d});
    G[t].push_back({s, d});
  }
  ll ok = 0;
  ll ng = 1e9 + 1;
  ll ans = -1;
  while (ng - ok > 1) {
    ll mid = (ok + ng) / 2;
    vector<ll> d(n, -1);
    d[0] = 0;
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
      auto u = q.front();
      q.pop();
      for (auto e : G[u]) {
        if (e.second < mid) {
          continue;
        }
        int next = e.first;
        if (d[next] >= 0) {
          continue;
        }
        d[next] = d[u] + 1;
        q.push(next);
      }
    }
    if (d[n - 1] >= 0) {
      ok = mid;
      ans = d[n - 1];
    } else {
      ng = mid;
    }
  }
  cout << ok << " " << ans << endl;

  return 0;
}
0