結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | carrot46 |
提出日時 | 2021-04-09 22:33:55 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 74 ms / 2,000 ms |
コード長 | 2,580 bytes |
コンパイル時間 | 2,627 ms |
コンパイル使用メモリ | 221,124 KB |
実行使用メモリ | 14,596 KB |
最終ジャッジ日時 | 2023-09-07 12:04:51 |
合計ジャッジ時間 | 6,775 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 68 ms
13,112 KB |
testcase_03 | AC | 51 ms
10,884 KB |
testcase_04 | AC | 34 ms
8,764 KB |
testcase_05 | AC | 14 ms
5,020 KB |
testcase_06 | AC | 54 ms
10,876 KB |
testcase_07 | AC | 68 ms
14,596 KB |
testcase_08 | AC | 74 ms
13,892 KB |
testcase_09 | AC | 68 ms
13,800 KB |
testcase_10 | AC | 37 ms
7,196 KB |
testcase_11 | AC | 37 ms
7,336 KB |
testcase_12 | AC | 36 ms
7,152 KB |
testcase_13 | AC | 24 ms
6,256 KB |
testcase_14 | AC | 18 ms
4,764 KB |
testcase_15 | AC | 33 ms
6,336 KB |
testcase_16 | AC | 36 ms
6,144 KB |
testcase_17 | AC | 4 ms
4,376 KB |
testcase_18 | AC | 6 ms
4,380 KB |
testcase_19 | AC | 30 ms
6,816 KB |
testcase_20 | AC | 43 ms
10,836 KB |
testcase_21 | AC | 45 ms
8,016 KB |
testcase_22 | AC | 52 ms
12,032 KB |
testcase_23 | AC | 45 ms
11,404 KB |
testcase_24 | AC | 44 ms
10,688 KB |
testcase_25 | AC | 54 ms
11,788 KB |
testcase_26 | AC | 57 ms
12,220 KB |
testcase_27 | AC | 22 ms
5,844 KB |
testcase_28 | AC | 63 ms
13,560 KB |
testcase_29 | AC | 39 ms
7,960 KB |
testcase_30 | AC | 46 ms
8,924 KB |
testcase_31 | AC | 62 ms
13,588 KB |
testcase_32 | AC | 46 ms
10,980 KB |
testcase_33 | AC | 40 ms
9,876 KB |
testcase_34 | AC | 23 ms
6,688 KB |
testcase_35 | AC | 23 ms
6,192 KB |
testcase_36 | AC | 40 ms
8,908 KB |
testcase_37 | AC | 47 ms
10,668 KB |
testcase_38 | AC | 10 ms
4,396 KB |
testcase_39 | AC | 37 ms
6,192 KB |
testcase_40 | AC | 36 ms
7,200 KB |
testcase_41 | AC | 34 ms
6,204 KB |
testcase_42 | AC | 33 ms
6,960 KB |
testcase_43 | AC | 38 ms
10,560 KB |
testcase_44 | AC | 41 ms
10,576 KB |
testcase_45 | AC | 40 ms
10,704 KB |
testcase_46 | AC | 48 ms
10,684 KB |
testcase_47 | AC | 59 ms
11,632 KB |
testcase_48 | AC | 54 ms
11,196 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/modint> using namespace atcoder; //#pragma GCC optimize("O3") using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() using ll = long long; using vec = vector<ll>; using mat = vector<vec>; ll N,M,H,W,Q,K,A,B; string S; using P = pair<ll, ll>; using tp = tuple<ll, ll, ll>; const ll INF = (1LL<<61); template<class T> bool chmin(T &a, const T b){ if(a > b) {a = b; return true;} else return false; } template<class T> bool chmax(T &a, const T b){ if(a < b) {a = b; return true;} else return false; } template<class T> void my_printv(std::vector<T> v,bool endline = true){ if(!v.empty()){ for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" "; std::cout<<v.back(); } if(endline) std::cout<<std::endl; } class union_find{ vector<long> parent, tree_size; public: union_find(unsigned long _n) : parent(_n), tree_size(_n, 1){ for(unsigned long i = 0; i < _n; ++i)parent[i] = i; } ll find(ll x){ while(parent[x] != x)x = parent[x] = parent[parent[x]]; return x; } void merge(ll a, ll b){ a = find(a); b = find(b); if(a==b) return; if(tree_size[a] < tree_size[b])swap(a, b); tree_size[a] += tree_size[b]; parent[b] = a; return; } bool same(ll a, ll b){ a = find(a); b = find(b); return a == b; } }; //uf.mergeのように使う //ufはMAX_N+1でとるか、代入時に0-indexedにする int solve(mat &G){ vec dist(N, INF); queue<P> que; que.emplace(0, 0); while(!que.empty()){ auto [d, v] = que.front(); que.pop(); for(int to : G[v]) if(chmin(dist[to], d + 1)) que.emplace(d + 1, to); } return dist[N - 1]; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin>>N>>M; mat G(N); vector<tp> es; rep(i, M){ int s, t, d; cin>>s>>t>>d; --s; --t; es.emplace_back(s, t, d); } sort(ALL(es), [](auto a, auto b){ return get<2>(a) > get<2>(b); }); union_find uf(N); int w = -1; for(auto [s, t, d] : es){ if(d < w) break; G[s].push_back(t); G[t].push_back(s); uf.merge(s, t); if(w == -1 && uf.same(0, N - 1)) w = d; } cout<<w<<' '<<solve(G)<<endl; }