結果

問題 No.1473 おでぶなおばけさん
ユーザー ninoinuininoinui
提出日時 2021-04-09 21:43:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,276 ms / 2,000 ms
コード長 4,814 bytes
コンパイル時間 2,680 ms
コンパイル使用メモリ 217,732 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2023-09-07 10:36:21
合計ジャッジ時間 19,908 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 846 ms
13,048 KB
testcase_03 AC 436 ms
10,604 KB
testcase_04 AC 484 ms
8,552 KB
testcase_05 AC 139 ms
5,176 KB
testcase_06 AC 569 ms
11,100 KB
testcase_07 AC 916 ms
13,596 KB
testcase_08 AC 1,276 ms
13,588 KB
testcase_09 AC 1,089 ms
13,640 KB
testcase_10 AC 37 ms
6,440 KB
testcase_11 AC 36 ms
7,216 KB
testcase_12 AC 37 ms
6,740 KB
testcase_13 AC 21 ms
5,540 KB
testcase_14 AC 16 ms
4,880 KB
testcase_15 AC 29 ms
6,576 KB
testcase_16 AC 34 ms
6,472 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 67 ms
5,276 KB
testcase_20 AC 230 ms
10,328 KB
testcase_21 AC 183 ms
8,476 KB
testcase_22 AC 121 ms
12,976 KB
testcase_23 AC 107 ms
11,008 KB
testcase_24 AC 97 ms
11,268 KB
testcase_25 AC 603 ms
12,356 KB
testcase_26 AC 638 ms
12,552 KB
testcase_27 AC 109 ms
6,976 KB
testcase_28 AC 920 ms
13,448 KB
testcase_29 AC 308 ms
11,264 KB
testcase_30 AC 533 ms
12,472 KB
testcase_31 AC 620 ms
13,516 KB
testcase_32 AC 331 ms
10,936 KB
testcase_33 AC 293 ms
9,848 KB
testcase_34 AC 166 ms
7,036 KB
testcase_35 AC 90 ms
5,596 KB
testcase_36 AC 263 ms
10,164 KB
testcase_37 AC 449 ms
10,616 KB
testcase_38 AC 54 ms
4,792 KB
testcase_39 AC 35 ms
6,332 KB
testcase_40 AC 34 ms
6,412 KB
testcase_41 AC 30 ms
5,836 KB
testcase_42 AC 30 ms
5,752 KB
testcase_43 AC 179 ms
10,216 KB
testcase_44 AC 182 ms
10,220 KB
testcase_45 AC 179 ms
10,096 KB
testcase_46 AC 456 ms
10,616 KB
testcase_47 AC 635 ms
12,128 KB
testcase_48 AC 557 ms
11,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef _DEBUG
#define _DEBUG
#include __FILE__

signed main() {
  int N, M;
  cin >> N >> M;
  vector<tuple<int, int, int>> V(M);
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c, a--, b--;
    V.at(i) = {a, b, c};
  }

  auto f = [&](long mid) {
    Dijkstra<long> D(N);
    for (const auto& [a, b, c] : V) {
      if (c >= mid) D.add_edge(a, b, 1);
    }
    auto ans = D.solve(0).at(N - 1);
    if (ans == LONG_MAX) return false;
    return true;
  };
  long ok = 0, ng = INT_MAX;
  while (abs(ok - ng) > 1) {
    long mid = (ok + ng) / 2;
    (f(mid)) ? ok = mid : ng = mid;
  }

  auto f2 = [&](long mid) {
    Dijkstra<long> D(N);
    for (const auto& [a, b, c] : V) {
      if (c >= mid) D.add_edge(a, b, 1);
    }
    auto ans = D.solve(0).at(N - 1);
    return ans;
  };

  cout << ok << " " << f2(ok) << "\n";
}

#else
// #undef _DEBUG
#pragma GCC diagnostic warning "-Wextra"
#pragma GCC diagnostic warning "-Wshadow"
#include <bits/stdc++.h>
using namespace std;

template <typename T> class Dijkstra {
private:
  using edge = tuple<int, T>;
  vector<vector<edge>> G;
  vector<T> D;

public:
  Dijkstra(int v) : G(v), D(v, numeric_limits<T>::max()) {}

  void add_edge(int from, int to, T cost) {
    G[from].push_back({to, cost});
    G[to].push_back({from, cost});
  }

  vector<T> solve(int s) {
    D[s] = 0;
    using pti = pair<T, int>;
    priority_queue<pti, vector<pti>, greater<pti>> que;
    que.push({0, s});
    while (que.size()) {
      auto [dist, now] = que.top();
      que.pop();
      if (dist > D[now]) continue;
      for (const auto& [to, cost] : G[now]) {
        if (D[now] + cost < D[to]) {
          D[to] = D[now] + cost;
          que.push({D[to], to});
        }
      }
    }
    return D;
  }
};

struct io_setup {
  io_setup() { cin.tie(nullptr)->sync_with_stdio(false); }
} io_setup;

template <class A, class B> bool cmin(A& a, const B& b) {
  if (a > b) return a = b, true;
  return false;
}

template <class A, class B> bool cmax(A& a, const B& b) {
  if (a < b) return a = b, true;
  return false;
}

template <class A, class B> ostream& operator<<(ostream& os, const pair<A, B>& p);

template <class A, class B, class C> ostream& operator<<(ostream& os, const tuple<A, B, C>& t);

template <class A, class B, class C, class D> ostream& operator<<(ostream& os, const tuple<A, B, C, D>& t);

#define foreach(it, a) for (auto it = a.begin(); it != a.end(); it++)

ostream& operator<<(ostream& os, const vector<char>& vec) {
  os << "{";
  foreach (it, vec) { os << (it == vec.begin() ? "" : " ") << *it; }
  return os << "}";
}

template <class A> ostream& operator<<(ostream& os, const vector<A>& vec) {
  os << "{";
  foreach (it, vec) { os << (it == vec.begin() ? "" : ", ") << *it; }
  return os << "}";
}

template <class A> ostream& operator<<(ostream& os, const vector<vector<A> >& vec) {
  os << "{\n";
  foreach (it, vec) { os << (it == vec.begin() ? " " : "\n ") << *it; }
  return os << "\n}";
}

template <class A> ostream& operator<<(ostream& os, const vector<vector<vector<A> > >& vec) {
  os << "{\n";
  foreach (it, vec) { os << (it == vec.begin() ? "" : "\n") << it - vec.begin() << ": " << *it; }
  return os << "\n}";
}

template <class A> ostream& operator<<(ostream& os, const set<A>& se) {
  os << "{";
  foreach (it, se) { os << (it == se.begin() ? "" : ", ") << *it; }
  return os << "}";
}

template <class A> ostream& operator<<(ostream& os, const multiset<A>& ms) {
  os << "{";
  foreach (it, ms) { os << (it == ms.begin() ? "" : ", ") << *it; }
  return os << "}";
}

template <class A, class B> ostream& operator<<(ostream& os, const map<A, B>& ma) {
  os << "{";
  foreach (it, ma) { os << (it == ma.begin() ? "" : ", ") << *it; }
  return os << "}";
}

template <class A> ostream& operator<<(ostream& os, priority_queue<A> pq) {
  os << "{";
  while (!pq.empty()) {
    os << pq.top(), pq.pop();
    if (!pq.empty()) os << ", ";
  }
  return os << "}";
}

template <class A, class B> ostream& operator<<(ostream& os, const pair<A, B>& p) {
  const auto& [a, b] = p;
  return os << "(" << a << ", " << b << ")";
}

template <class A, class B, class C> ostream& operator<<(ostream& os, const tuple<A, B, C>& t) {
  const auto& [a, b, c] = t;
  return os << "(" << a << ", " << b << ", " << c << ")";
}

template <class A, class B, class C, class D> ostream& operator<<(ostream& os, const tuple<A, B, C, D>& t) {
  const auto& [a, b, c, d] = t;
  return os << "(" << a << ", " << b << ", " << c << ", " << d << ")";
}

void dump_func() {}
template <class A, class... B> void dump_func(const A& a, const B&... b) {
  cout << a << (sizeof...(b) ? ", " : "\n");
  dump_func(b...);
}

#ifdef _DEBUG
#define dump(...) cout << "[" << (#__VA_ARGS__) << "]: ", dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
#endif
0