結果
問題 | No.1833 Subway Planning |
ユーザー | 👑 kmjp |
提出日時 | 2022-02-04 23:51:21 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 749 ms / 4,000 ms |
コード長 | 1,643 bytes |
コンパイル時間 | 2,496 ms |
コンパイル使用メモリ | 203,456 KB |
実行使用メモリ | 30,020 KB |
最終ジャッジ日時 | 2023-09-02 06:10:59 |
合計ジャッジ時間 | 10,958 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
8,068 KB |
testcase_01 | AC | 5 ms
8,084 KB |
testcase_02 | AC | 4 ms
8,092 KB |
testcase_03 | AC | 4 ms
8,092 KB |
testcase_04 | AC | 186 ms
25,080 KB |
testcase_05 | AC | 266 ms
29,960 KB |
testcase_06 | AC | 234 ms
30,020 KB |
testcase_07 | AC | 655 ms
29,024 KB |
testcase_08 | AC | 647 ms
29,772 KB |
testcase_09 | AC | 749 ms
29,692 KB |
testcase_10 | AC | 141 ms
15,600 KB |
testcase_11 | AC | 113 ms
15,748 KB |
testcase_12 | AC | 116 ms
15,896 KB |
testcase_13 | AC | 150 ms
15,608 KB |
testcase_14 | AC | 130 ms
15,928 KB |
testcase_15 | AC | 337 ms
15,964 KB |
testcase_16 | AC | 316 ms
17,528 KB |
testcase_17 | AC | 531 ms
15,944 KB |
testcase_18 | AC | 470 ms
15,440 KB |
testcase_19 | AC | 328 ms
15,568 KB |
testcase_20 | AC | 314 ms
13,848 KB |
testcase_21 | AC | 487 ms
23,936 KB |
testcase_22 | AC | 297 ms
20,352 KB |
testcase_23 | AC | 4 ms
8,096 KB |
testcase_24 | AC | 5 ms
8,092 KB |
testcase_25 | AC | 4 ms
8,144 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N; vector<pair<int,int>> E[202020]; pair<int,int> hoge(int cur,int pre,int v) { pair<int,int> p={1<<30,-1}; FORR2(e,c,E[cur]) if(e!=pre) { auto q=hoge(e,cur,v); if(q.second>v||c>v) { q.first=min(q.first,c); q.second=max(q.second,c); } if(p.second>v&&q.second>v) { return {-1,1<<30}; } else if(q.second>=v) { p=q; } } return p; } int can(int v) { int i; FOR(i,N) { FORR2(e,c,E[i]) if(c>v) { pair<int,int> A=hoge(e,i,v); pair<int,int> B=hoge(i,e,v); return (max({c,A.second,B.second})-min({c,A.first,B.first}))<=v; } } return 1; } void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(i,N-1) { cin>>x>>y>>r; E[x-1].push_back({y-1,r}); E[y-1].push_back({x-1,r}); } int ret=(1<<30)-1; for(i=29;i>=0;i--) if(can(ret-(1<<i))) ret-=1<<i; cout<<ret<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }