結果
| 問題 |
No.1473 おでぶなおばけさん
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2021-04-09 22:03:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 102 ms / 2,000 ms |
| コード長 | 1,487 bytes |
| コンパイル時間 | 6,235 ms |
| コンパイル使用メモリ | 260,108 KB |
| 最終ジャッジ日時 | 2025-01-20 14:24:18 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 47 |
ソースコード
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
struct Edge {
int u, v, w;
bool operator<(const Edge& x) const {
return w < x.w;
}
};
vector<Edge> es(m);
for(auto& e: es) cin >> e.u >> e.v >> e.w, e.u--, e.v--;
sort(rall(es));
dsu d(n);
VVI to(n);
int pre = -1;
for(auto e: es) {
if (pre != e.w && d.same(0, n - 1)) break;
to[e.u].push_back(e.v);
to[e.v].push_back(e.u);
d.merge(e.u, e.v);
pre = e.w;
}
cout << pre << ' ';
VI dist(n, -1);
queue<int> q;
auto push = [&](int i, int c) {
if (dist[i] == -1) {
dist[i] = c;
q.push(i);
}
};
push(0, 0);
while(!q.empty()) {
int u = q.front(); q.pop();
int nc = dist[u] + 1;
for(int v: to[u]) push(v, nc);
}
cout << dist[n - 1] << '\n';
}
Kude