結果

問題 No.1473 おでぶなおばけさん
ユーザー masutech16masutech16
提出日時 2021-04-10 17:50:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 702 ms / 2,000 ms
コード長 2,685 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 211,016 KB
実行使用メモリ 10,964 KB
最終ジャッジ日時 2023-09-08 13:34:22
合計ジャッジ時間 17,338 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 578 ms
10,376 KB
testcase_03 AC 397 ms
9,068 KB
testcase_04 AC 313 ms
7,072 KB
testcase_05 AC 93 ms
4,404 KB
testcase_06 AC 426 ms
9,564 KB
testcase_07 AC 629 ms
10,796 KB
testcase_08 AC 702 ms
10,964 KB
testcase_09 AC 641 ms
10,808 KB
testcase_10 AC 90 ms
6,176 KB
testcase_11 AC 89 ms
6,480 KB
testcase_12 AC 90 ms
6,412 KB
testcase_13 AC 54 ms
5,452 KB
testcase_14 AC 39 ms
4,776 KB
testcase_15 AC 76 ms
6,188 KB
testcase_16 AC 89 ms
6,144 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 13 ms
4,380 KB
testcase_19 AC 93 ms
6,120 KB
testcase_20 AC 197 ms
8,364 KB
testcase_21 AC 167 ms
7,420 KB
testcase_22 AC 101 ms
9,724 KB
testcase_23 AC 85 ms
8,960 KB
testcase_24 AC 87 ms
8,524 KB
testcase_25 AC 587 ms
9,448 KB
testcase_26 AC 534 ms
9,380 KB
testcase_27 AC 183 ms
5,368 KB
testcase_28 AC 602 ms
10,688 KB
testcase_29 AC 459 ms
8,376 KB
testcase_30 AC 530 ms
9,356 KB
testcase_31 AC 375 ms
10,664 KB
testcase_32 AC 261 ms
9,352 KB
testcase_33 AC 204 ms
8,096 KB
testcase_34 AC 110 ms
5,976 KB
testcase_35 AC 89 ms
5,400 KB
testcase_36 AC 388 ms
7,540 KB
testcase_37 AC 410 ms
8,588 KB
testcase_38 AC 68 ms
4,380 KB
testcase_39 AC 89 ms
6,440 KB
testcase_40 AC 88 ms
6,292 KB
testcase_41 AC 75 ms
6,320 KB
testcase_42 AC 77 ms
6,196 KB
testcase_43 AC 205 ms
8,972 KB
testcase_44 AC 205 ms
8,964 KB
testcase_45 AC 207 ms
8,880 KB
testcase_46 AC 403 ms
8,096 KB
testcase_47 AC 500 ms
8,900 KB
testcase_48 AC 456 ms
8,576 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]) {
        if (reached[u])
          continue;
        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