結果
問題 |
No.1473 おでぶなおばけさん
|
ユーザー |
|
提出日時 | 2023-03-13 09:04:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 75 ms / 2,000 ms |
コード長 | 1,032 bytes |
コンパイル時間 | 2,321 ms |
コンパイル使用メモリ | 204,180 KB |
最終ジャッジ日時 | 2025-02-11 10:49:40 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 47 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 11; vector <int> e[N]; struct edge { int u, v, w; bool operator <(const edge &e) const { return w > e.w; } }a[N]; int p[N]; int find(int x) { if(p[x] == x) return x; return p[x] = find(p[x]); } int dis[N]; int main() { ios::sync_with_stdio(0); int n, m; cin >> n >> m; for(int i = 0; i < m; i ++) { cin >> a[i].u >> a[i].v >> a[i].w; } sort(a, a + m); iota(p, p + n + 1, 0); auto add = [&](int u, int v) { e[u].push_back(v); e[v].push_back(u); u = find(u); v = find(v); if(u != v) p[u] = v; }; int p = 0, w = 0; while(find(1) != find(n)) { w = a[p].w; add(a[p].u, a[p].v); p ++; } while(p != m && a[p].w == w) { add(a[p].u, a[p].v); p ++; } fill(dis, dis + n + 1, 1e8); dis[1] = 0; queue <int> q; q.push(1); while(!q.empty()) { int x = q.front(); q.pop(); for(int i : e[x]) { if(dis[i] > dis[x] + 1) { dis[i] = dis[x] + 1; q.push(i); } } } cout << w << ' ' << dis[n] << '\n'; }