結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | fumofumofuni |
提出日時 | 2021-04-09 21:48:53 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 186 ms / 2,000 ms |
コード長 | 2,374 bytes |
コンパイル時間 | 2,240 ms |
コンパイル使用メモリ | 212,596 KB |
実行使用メモリ | 12,540 KB |
最終ジャッジ日時 | 2023-09-07 10:49:09 |
合計ジャッジ時間 | 9,368 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 173 ms
11,580 KB |
testcase_03 | AC | 143 ms
9,740 KB |
testcase_04 | AC | 94 ms
7,892 KB |
testcase_05 | AC | 34 ms
4,564 KB |
testcase_06 | AC | 154 ms
9,840 KB |
testcase_07 | AC | 185 ms
12,320 KB |
testcase_08 | AC | 186 ms
12,540 KB |
testcase_09 | AC | 182 ms
12,308 KB |
testcase_10 | AC | 84 ms
5,396 KB |
testcase_11 | AC | 83 ms
5,504 KB |
testcase_12 | AC | 84 ms
5,516 KB |
testcase_13 | AC | 52 ms
4,612 KB |
testcase_14 | AC | 37 ms
4,380 KB |
testcase_15 | AC | 71 ms
5,140 KB |
testcase_16 | AC | 82 ms
5,520 KB |
testcase_17 | AC | 7 ms
4,376 KB |
testcase_18 | AC | 11 ms
4,376 KB |
testcase_19 | AC | 65 ms
5,900 KB |
testcase_20 | AC | 96 ms
8,780 KB |
testcase_21 | AC | 101 ms
7,324 KB |
testcase_22 | AC | 97 ms
10,960 KB |
testcase_23 | AC | 83 ms
9,776 KB |
testcase_24 | AC | 83 ms
9,548 KB |
testcase_25 | AC | 166 ms
10,784 KB |
testcase_26 | AC | 179 ms
10,860 KB |
testcase_27 | AC | 59 ms
5,892 KB |
testcase_28 | AC | 160 ms
11,848 KB |
testcase_29 | AC | 109 ms
7,428 KB |
testcase_30 | AC | 140 ms
7,996 KB |
testcase_31 | AC | 150 ms
12,016 KB |
testcase_32 | AC | 120 ms
9,908 KB |
testcase_33 | AC | 101 ms
8,808 KB |
testcase_34 | AC | 54 ms
6,292 KB |
testcase_35 | AC | 55 ms
5,716 KB |
testcase_36 | AC | 100 ms
8,340 KB |
testcase_37 | AC | 108 ms
9,340 KB |
testcase_38 | AC | 23 ms
4,396 KB |
testcase_39 | AC | 84 ms
5,404 KB |
testcase_40 | AC | 88 ms
5,400 KB |
testcase_41 | AC | 72 ms
5,360 KB |
testcase_42 | AC | 73 ms
5,352 KB |
testcase_43 | AC | 98 ms
9,204 KB |
testcase_44 | AC | 97 ms
9,316 KB |
testcase_45 | AC | 98 ms
9,260 KB |
testcase_46 | AC | 141 ms
9,372 KB |
testcase_47 | AC | 174 ms
10,592 KB |
testcase_48 | AC | 152 ms
9,932 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0;i<n;i++) #define repl(i,l,r) for(ll i=(l);i<(r);i++) #define per(i,n) for(ll i=(n)-1;i>=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define pqueue(x) priority_queue<x,vector<x>,greater<x>> #define all(x) (x).begin(),(x).end() #define CST(x) cout<<fixed<<setprecision(x) #define rev(x) reverse(x); using ll=long long; using vl=vector<ll>; using vvl=vector<vector<ll>>; using pl=pair<ll,ll>; using vpl=vector<pl>; using vvpl=vector<vpl>; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[8]={-1,0,1,0,1,1,-1,-1}; const ll dx[8]={0,-1,0,1,1,-1,1,-1}; template <typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template <typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } struct UnionFind { vector<int> par; vector<int> edge; UnionFind(int n) : par(n, -1),edge(n, 0) {} int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool same(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) { edge[x]++; return false; } if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; edge[x] += edge[y]+1; return true; } int size(int x) { return -par[root(x)]; } }; struct edge{ ll s,t,w; }; int main(){ ll n,m;cin >> n >>m; ll ok=0,ng=inf; vector<edge> es(m); rep(i,m){ ll a,b,c;cin >> a >> b >> c;a--;b--;es[i]={a,b,c}; } while(ng-ok>1){ ll mid=(ok+ng)/2; UnionFind uf(n); rep(i,m){ if(es[i].w>=mid)uf.merge(es[i].s,es[i].t); } if(uf.same(0,n-1))ok=mid; else ng=mid; } //cout << ok <<endl; vvl g(n);rep(i,m){ if(ok<=es[i].w){ g[es[i].s].pb(es[i].t); g[es[i].t].pb(es[i].s); } } vl dist(n,-1); dist[0]=0; queue<ll> que; que.push(0); while(!que.empty()){ ll v=que.front();que.pop(); for(auto p:g[v]){ if(dist[p]!=-1)continue; dist[p]=dist[v]+1; que.push(p); } } cout << ok <<" " << dist[n-1] <<endl; }