結果
問題 | No.1833 Subway Planning |
ユーザー | riano |
提出日時 | 2022-01-23 15:56:51 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 500 ms / 4,000 ms |
コード長 | 1,731 bytes |
コンパイル時間 | 1,627 ms |
コンパイル使用メモリ | 178,256 KB |
実行使用メモリ | 49,280 KB |
最終ジャッジ日時 | 2024-05-07 04:10:01 |
合計ジャッジ時間 | 10,987 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 254 ms
49,280 KB |
testcase_05 | AC | 257 ms
49,280 KB |
testcase_06 | AC | 362 ms
34,816 KB |
testcase_07 | AC | 466 ms
40,320 KB |
testcase_08 | AC | 500 ms
44,672 KB |
testcase_09 | AC | 313 ms
49,280 KB |
testcase_10 | AC | 360 ms
27,440 KB |
testcase_11 | AC | 233 ms
27,448 KB |
testcase_12 | AC | 244 ms
27,352 KB |
testcase_13 | AC | 359 ms
27,448 KB |
testcase_14 | AC | 335 ms
29,040 KB |
testcase_15 | AC | 269 ms
28,928 KB |
testcase_16 | AC | 492 ms
29,056 KB |
testcase_17 | AC | 470 ms
28,788 KB |
testcase_18 | AC | 449 ms
27,136 KB |
testcase_19 | AC | 287 ms
28,272 KB |
testcase_20 | AC | 200 ms
22,548 KB |
testcase_21 | AC | 391 ms
35,292 KB |
testcase_22 | AC | 352 ms
31,412 KB |
testcase_23 | AC | 1 ms
5,376 KB |
testcase_24 | AC | 1 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回数 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; }