結果
| 問題 |
No.1473 おでぶなおばけさん
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-15 18:10:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 65 ms / 2,000 ms |
| コード長 | 1,082 bytes |
| コンパイル時間 | 2,237 ms |
| コンパイル使用メモリ | 213,444 KB |
| 最終ジャッジ日時 | 2025-02-24 08:49:40 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 47 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#include<atcoder/dsu>
using namespace atcoder;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N,M;
cin>>N>>M;
dsu d(N);
vector<pair<int,pair<int,int>>> E(M);
for(int i=0;i<M;i++){
cin>>E[i].second.first>>E[i].second.second>>E[i].first;
E[i].second={E[i].second.first-1,E[i].second.second-1};
}
sort(E.begin(),E.end());
reverse(E.begin(),E.end());
vector<vector<int>> G(N);
int W=-1;
for(int i=0;i<M;i++){
if(E[i].first<W)break;
auto [u,v]=E[i].second;
G[u].push_back(v);
G[v].push_back(u);
d.merge(u,v);
if(d.same(0,N-1)){
W=E[i].first;
}
}
vector<int> D(N,1e8);
queue<int> Q;
Q.push(0);
D[0]=0;
while(!Q.empty()){
int p=Q.front();
Q.pop();
for(auto v:G[p]){
if(D[v]>D[p]+1){
D[v]=D[p]+1;
Q.push(v);
}
}
}
cout<<W<<" "<<D[N-1]<<endl;
}