結果

問題 No.1473 おでぶなおばけさん
ユーザー yansi819yansi819
提出日時 2024-04-28 18:38:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 1,237 bytes
コンパイル時間 4,955 ms
コンパイル使用メモリ 276,168 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-28 18:38:34
合計ジャッジ時間 12,323 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 131 ms
10,624 KB
testcase_03 AC 106 ms
9,088 KB
testcase_04 AC 70 ms
7,552 KB
testcase_05 AC 26 ms
6,944 KB
testcase_06 AC 117 ms
8,960 KB
testcase_07 AC 135 ms
11,136 KB
testcase_08 AC 139 ms
11,264 KB
testcase_09 AC 135 ms
11,264 KB
testcase_10 AC 93 ms
6,940 KB
testcase_11 AC 91 ms
6,940 KB
testcase_12 AC 92 ms
6,944 KB
testcase_13 AC 58 ms
6,944 KB
testcase_14 AC 42 ms
6,944 KB
testcase_15 AC 78 ms
6,944 KB
testcase_16 AC 90 ms
6,940 KB
testcase_17 AC 8 ms
6,940 KB
testcase_18 AC 12 ms
6,944 KB
testcase_19 AC 67 ms
6,940 KB
testcase_20 AC 83 ms
8,448 KB
testcase_21 AC 93 ms
6,940 KB
testcase_22 AC 95 ms
9,344 KB
testcase_23 AC 78 ms
9,088 KB
testcase_24 AC 76 ms
8,448 KB
testcase_25 AC 116 ms
9,088 KB
testcase_26 AC 122 ms
8,960 KB
testcase_27 AC 49 ms
6,944 KB
testcase_28 AC 127 ms
10,880 KB
testcase_29 AC 92 ms
6,940 KB
testcase_30 AC 114 ms
7,296 KB
testcase_31 AC 124 ms
10,880 KB
testcase_32 AC 101 ms
8,960 KB
testcase_33 AC 82 ms
8,064 KB
testcase_34 AC 44 ms
6,944 KB
testcase_35 AC 50 ms
6,944 KB
testcase_36 AC 90 ms
6,944 KB
testcase_37 AC 89 ms
8,704 KB
testcase_38 AC 20 ms
6,944 KB
testcase_39 AC 90 ms
6,940 KB
testcase_40 AC 92 ms
6,944 KB
testcase_41 AC 81 ms
6,948 KB
testcase_42 AC 81 ms
6,944 KB
testcase_43 AC 95 ms
8,192 KB
testcase_44 AC 94 ms
8,192 KB
testcase_45 AC 93 ms
8,192 KB
testcase_46 AC 99 ms
8,064 KB
testcase_47 AC 122 ms
9,088 KB
testcase_48 AC 105 ms
8,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

int main() {
  int n, m; cin >> n >> m;
  vector<tuple<int, int, int>> edge(m);
  for (int i = 0; i < m; i++) {
    cin >> get<0>(edge[i]) >> get<1>(edge[i]) >> get<2>(edge[i]);
  }
  sort(edge.begin(), edge.end(), [&](auto a, auto b) {
    return get<2>(a) > get<2>(b);
  });
  int w = 0;
  dsu uf(n);
  for (int i = 0; i < m; i++) {
    auto [s, t, d] = edge[i];
    s--, t--;
    uf.merge(s, t);
    if (uf.same(0, n - 1)) {
      w = d;
      break;
    }
  }
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    auto [s, t, d] = edge[i];
    s--, t--;
    if (w <= d) {
      g[s].push_back(t);
      g[t].push_back(s);
    }
  }
  vector<ll> dist(n, 1e18);
  vector<bool> vis(n, false);
  dist[0] = 0;
  vis[0] = true;
  queue<int> que;
  que.push(0);
  while (!que.empty()) {
    int u = que.front(); que.pop();
    for (int v: g[u]) {
      if (vis[v]) continue;
      if (dist[v] > dist[u] + 1) {
        vis[v] = true;
        dist[v] = dist[u] + 1;
        que.push(v);
      }
    }
  }
  cout << w << ' ' << dist[n - 1] << endl;
  return 0;
}
0