結果

問題 No.1473 おでぶなおばけさん
ユーザー masutech16masutech16
提出日時 2021-04-10 17:41:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,003 ms / 2,000 ms
コード長 2,643 bytes
コンパイル時間 2,343 ms
コンパイル使用メモリ 210,008 KB
実行使用メモリ 10,984 KB
最終ジャッジ日時 2023-09-08 13:24:09
合計ジャッジ時間 19,557 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 755 ms
10,360 KB
testcase_03 AC 463 ms
9,048 KB
testcase_04 AC 338 ms
7,228 KB
testcase_05 AC 93 ms
4,488 KB
testcase_06 AC 472 ms
9,304 KB
testcase_07 AC 897 ms
10,860 KB
testcase_08 AC 1,003 ms
10,832 KB
testcase_09 AC 875 ms
10,984 KB
testcase_10 AC 89 ms
6,216 KB
testcase_11 AC 88 ms
6,684 KB
testcase_12 AC 88 ms
6,576 KB
testcase_13 AC 53 ms
5,588 KB
testcase_14 AC 39 ms
4,664 KB
testcase_15 AC 73 ms
6,388 KB
testcase_16 AC 86 ms
6,328 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 92 ms
6,312 KB
testcase_20 AC 212 ms
8,508 KB
testcase_21 AC 171 ms
7,404 KB
testcase_22 AC 110 ms
9,760 KB
testcase_23 AC 99 ms
8,948 KB
testcase_24 AC 95 ms
8,580 KB
testcase_25 AC 674 ms
9,848 KB
testcase_26 AC 619 ms
9,452 KB
testcase_27 AC 176 ms
5,672 KB
testcase_28 AC 851 ms
10,648 KB
testcase_29 AC 474 ms
8,640 KB
testcase_30 AC 549 ms
9,512 KB
testcase_31 AC 511 ms
10,724 KB
testcase_32 AC 301 ms
9,436 KB
testcase_33 AC 219 ms
7,984 KB
testcase_34 AC 114 ms
5,844 KB
testcase_35 AC 89 ms
5,728 KB
testcase_36 AC 393 ms
8,012 KB
testcase_37 AC 482 ms
8,656 KB
testcase_38 AC 67 ms
4,380 KB
testcase_39 AC 89 ms
6,708 KB
testcase_40 AC 87 ms
6,624 KB
testcase_41 AC 74 ms
6,236 KB
testcase_42 AC 74 ms
6,552 KB
testcase_43 AC 208 ms
9,120 KB
testcase_44 AC 207 ms
9,100 KB
testcase_45 AC 208 ms
9,272 KB
testcase_46 AC 433 ms
7,984 KB
testcase_47 AC 535 ms
9,028 KB
testcase_48 AC 480 ms
8,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "/workspaces/compro/lib/template.hpp"


#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  int size = v.size();
  for (int i = 0; i < size; i++) {
    std::cout << v[i];
    if (i != size - 1)
      std::cout << " ";
  }
  return out;
}

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "main.cpp"

std::pair<long long, long long> solve(long long n, int m, const std::vector<long long> &s,
                                      const std::vector<long long> &t, const std::vector<long long> &d) {
  ll ng = 0;
  REP(i, m) { chmax(ng, d[i] + 1); }

  ll ok = 0;

  auto f = [&](ll x) {
    vector<vector<int>> g(n);
    REP(i, m) {
      if (x > d[i])
        continue;
      g[s[i]].push_back(t[i]);
      g[t[i]].push_back(s[i]);
    }

    queue<pair<int, int>> q;
    q.push({0, 0});
    vector<bool> reached(n, false);
    while (!q.empty()) {
      auto [v, num] = q.front();
      q.pop();
      if (reached[v])
        continue;
      if (v == n - 1)
        return num;
      reached[v] = true;
      for (const auto &u : g[v]) {
        q.push({u, num + 1});
      }
    }
    return -1;
  };

  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if (f(mid) != -1) {
      ok = mid;
    } else {
      ng = mid;
    }
  }

  return {ok, f(ok)};
}

// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
  int n;
  int m;
  std::cin >> n >> m;
  std::vector<long long> s(m), t(m), d(m);
  for (int i = 0; i < m; ++i) {
    std::cin >> s[i] >> t[i] >> d[i];
    s[i]--;
    t[i]--;
  }
  auto [c, e] = solve(n, m, s, t, d);
  std::cout << c << ' ' << e << std::endl;
  return 0;
}
0