結果
問題 | No.1833 Subway Planning |
ユーザー | riano |
提出日時 | 2021-12-19 01:12:03 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 604 ms / 4,000 ms |
コード長 | 1,755 bytes |
コンパイル時間 | 1,926 ms |
コンパイル使用メモリ | 178,860 KB |
実行使用メモリ | 49,280 KB |
最終ジャッジ日時 | 2024-09-15 14:33:53 |
合計ジャッジ時間 | 12,722 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 284 ms
49,152 KB |
testcase_05 | AC | 289 ms
49,280 KB |
testcase_06 | AC | 437 ms
34,816 KB |
testcase_07 | AC | 591 ms
40,320 KB |
testcase_08 | AC | 604 ms
44,672 KB |
testcase_09 | AC | 369 ms
49,152 KB |
testcase_10 | AC | 437 ms
27,320 KB |
testcase_11 | AC | 276 ms
27,324 KB |
testcase_12 | AC | 287 ms
27,444 KB |
testcase_13 | AC | 481 ms
27,448 KB |
testcase_14 | AC | 416 ms
28,928 KB |
testcase_15 | AC | 320 ms
28,928 KB |
testcase_16 | AC | 550 ms
28,996 KB |
testcase_17 | AC | 598 ms
28,672 KB |
testcase_18 | AC | 576 ms
27,008 KB |
testcase_19 | AC | 340 ms
28,272 KB |
testcase_20 | AC | 255 ms
22,528 KB |
testcase_21 | AC | 487 ms
35,288 KB |
testcase_22 | AC | 428 ms
31,408 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
コンパイルメッセージ
main.cpp: In function 'void dfs_insert(Graph&, int, int, int)': main.cpp:18:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 18 | for(auto[nx,c]:G[s]){ | ^ main.cpp: In function 'void dfs_calc(Graph&, int, int, int)': main.cpp:32:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 32 | for(auto[nx,c]:G[s]){ | ^ main.cpp: In function 'int main()': main.cpp:66:11: warning: 'mb' may be used uninitialized [-Wmaybe-uninitialized] 66 | vis[ma] = 0; dfs_insert(G,ma,0,mb); | ^ main.cpp:48:11: note: 'mb' was declared here 48 | ll ma,mb,mc = 0; | ^~ main.cpp:59:28: warning: 'ma' may be used uninitialized [-Wmaybe-uninitialized] 59 | vis[ma] = 0; dfs_insert(G,ma,0,mb); | ~~~~~~~~~~^~~~~~~~~~~ main.cpp:48:8: note: 'ma' was declared here 48 | ll ma,mb,mc = 0; | ^~
ソースコード
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(int i=0;i<n;i++) #define chmin(k,m) k = min(k,m) #define chmax(k,m) k = max(k,m) #define Pr pair<ll,ll> #define riano_ std::ios::sync_with_stdio(false);std::cin.tie(nullptr) using Graph = vector<vector<Pr>>; multiset<ll> in,out; ll tmp = 2e18; //dfs //s:始点 i:dfs回数 t:始点からの距離 vector<int> vis; void dfs_insert(Graph &G, int s,int i,int fbd){ for(auto[nx,c]:G[s]){ if(vis[nx]==i) continue; if(nx==fbd) continue; vis[nx] = i; out.insert(c); dfs_insert(G,nx,i,fbd); } } void dfs_calc(Graph &G, int s,int i,int fbd){ auto itr = in.end(); itr--; ll y = *itr; itr = in.begin(); ll x = *itr; itr = out.end(); itr--; ll z = *itr; chmin(tmp,max(z,y-x)); for(auto[nx,c]:G[s]){ if(vis[nx]==i) continue; if(nx==fbd) continue; vis[nx] = i; out.erase(out.find(c)); in.insert(c); dfs_calc(G,nx,i,fbd); in.erase(in.find(c)); out.insert(c); } } int main() { riano_; ll ans = 0; ll N; cin >> N; Graph G(N+1); ll ma,mb,mc = 0; rep(i,N-1){ ll a,b,c; cin >> a >> b >> c; G[a].emplace_back(b,c); G[b].emplace_back(a,c); if(c>mc){ mc = c; ma = a; mb = b; } } vis.assign(N+1,-1); in.insert(mc); out.insert(0); vis[ma] = 0; dfs_insert(G,ma,0,mb); vis[ma] = 1; dfs_calc(G,ma,1,mb); chmax(ans,tmp); swap(ma,mb); in.clear(); out.clear(); tmp = 2e18; vis.assign(N+1,-1); in.insert(mc); out.insert(0); vis[ma] = 0; dfs_insert(G,ma,0,mb); vis[ma] = 1; dfs_calc(G,ma,1,mb); chmax(ans,tmp); cout << ans << endl; }