結果
問題 | No.1833 Subway Planning |
ユーザー |
![]() |
提出日時 | 2021-12-19 01:12:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
コンパイルメッセージ
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; }