結果
| 問題 |
No.1473 おでぶなおばけさん
|
| コンテスト | |
| ユーザー |
uzzy
|
| 提出日時 | 2021-04-09 22:39:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 88 ms / 2,000 ms |
| コード長 | 1,880 bytes |
| コンパイル時間 | 2,861 ms |
| コンパイル使用メモリ | 200,376 KB |
| 実行使用メモリ | 15,744 KB |
| 最終ジャッジ日時 | 2024-06-25 06:17:42 |
| 合計ジャッジ時間 | 7,255 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 47 |
ソースコード
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
const int SZ = 100001;
class UF {
public:
int P[SZ + 1];
UF() : P() {
rep1(i, SZ) P[i] = -1;
}
int find(int A) {
if (P[A] < 0) return A;
return P[A] = find(P[A]);
}
bool unite(int A, int B) {
int a = find(A);
int b = find(B);
if (a == b) return false;
if (P[a] > P[b]) swap(a, b);
P[a] += P[b];
P[b] = a;
return true;
}
} uf;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
int kotae = 1e9;
tuple<int, int, int> tp[100000];
rep(i, M) {
int s, t, d;
cin >> s >> t >> d;
tp[i] = tie(d, s, t);
}
sort(tp, tp + M);
reverse(tp, tp + M);
#define PT pair<ll, int>
vector<PT> E[200001];
rep(i, M) if (uf.find(1) != uf.find(N) || kotae == get<0>(tp[i])) {
int d = get<0>(tp[i]);
int s = get<1>(tp[i]);
int t = get<2>(tp[i]);
uf.unite(s, t);
E[s].pb({ 1, t });
E[t].pb({ 1, s });
chmin(kotae, d);
}
ll D[100001];
rep1(i, N) D[i] = 1e18;
priority_queue<PT, vector<PT>, greater<PT>> que;
D[1] = 0;
que.push(mp(0, 1));
while (que.size()) {
PT p = que.top();
que.pop();
int i = p.second;
if (D[i] != p.first) continue;
for (PT p2 : E[i]) {
int j = p2.second;
ll d = D[i] + p2.first;
if (D[j] > d) {
D[j] = d;
que.push(mp(d, j));
}
}
}
cosp(kotae);
co(D[N]);
Would you please return 0;
}
uzzy