Submission #1692904
Source Code Expand
#include<cstdio> #include<algorithm> #include<vector> using namespace std; #define ll long long inline int read() { int x;char c; while((c=getchar())<'0'||c>'9'); for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0'; return x; } #define MN 131072 int n,l[MN+5],r[MN+5]; ll d[MN+5]; vector< pair<ll,ll> > v[MN+5],V; bool check(ll x) { for(int i=n;i;--i) { v[i].clear();V.clear(); if(!l[i]){v[i].push_back(make_pair(d[i],d[i]));continue;} if(v[l[i]].size()>v[r[i]].size())swap(l[i],r[i]); for(int j=0,k=0;j<v[l[i]].size();++j) { for(;k<v[r[i]].size()&&v[l[i]][j].first+v[r[i]][k].second-d[i]*2>x;++k); if(k==v[r[i]].size())break; V.push_back(make_pair(v[l[i]][j].second,v[r[i]][k].first)); V.push_back(make_pair(v[r[i]][k].first,v[l[i]][j].second)); } sort(V.begin(),V.end()); for(int j=0;j<V.size();++j)if(!j||V[j].second<V[j-1].second)v[i].push_back(V[j]); if(!v[i].size())return false; } return true; } int main() { int i,x;ll mid,ans; for(n=read(),i=2;i<=n;++i)x=read(),(l[x]?r[x]:l[x])=i,d[i]=d[x]+read(); for(ll l=0,r=1LL<<34;l<=r;)if(check(mid=l+r>>1))ans=mid,r=mid-1;else l=mid+1; printf("%lld",ans); }
Submission Info
Submission Time | |
---|---|
Task | E - Shik and Travel |
User | ditoly |
Language | C++14 (GCC 5.4.1) |
Score | 1400 |
Code Size | 1192 Byte |
Status | AC |
Exec Time | 465 ms |
Memory | 30196 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1400 / 1400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt, example2.txt, example3.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, example0.txt, example1.txt, example2.txt, example3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 5 ms | 4480 KB |
001.txt | AC | 5 ms | 4480 KB |
002.txt | AC | 5 ms | 4480 KB |
003.txt | AC | 5 ms | 4480 KB |
004.txt | AC | 5 ms | 4480 KB |
005.txt | AC | 5 ms | 4480 KB |
006.txt | AC | 5 ms | 4480 KB |
007.txt | AC | 5 ms | 4480 KB |
008.txt | AC | 5 ms | 4480 KB |
009.txt | AC | 5 ms | 4480 KB |
010.txt | AC | 155 ms | 10624 KB |
011.txt | AC | 162 ms | 10624 KB |
012.txt | AC | 157 ms | 10752 KB |
013.txt | AC | 161 ms | 10624 KB |
014.txt | AC | 143 ms | 10624 KB |
015.txt | AC | 157 ms | 10624 KB |
016.txt | AC | 159 ms | 10624 KB |
017.txt | AC | 160 ms | 10624 KB |
018.txt | AC | 162 ms | 10624 KB |
019.txt | AC | 155 ms | 10624 KB |
020.txt | AC | 155 ms | 10752 KB |
021.txt | AC | 157 ms | 10624 KB |
022.txt | AC | 159 ms | 10624 KB |
023.txt | AC | 158 ms | 10624 KB |
024.txt | AC | 156 ms | 10624 KB |
025.txt | AC | 157 ms | 10624 KB |
026.txt | AC | 142 ms | 9984 KB |
027.txt | AC | 153 ms | 10624 KB |
028.txt | AC | 142 ms | 9984 KB |
029.txt | AC | 140 ms | 9984 KB |
030.txt | AC | 140 ms | 10240 KB |
031.txt | AC | 168 ms | 10752 KB |
032.txt | AC | 162 ms | 10752 KB |
033.txt | AC | 139 ms | 10240 KB |
034.txt | AC | 140 ms | 10240 KB |
035.txt | AC | 163 ms | 10752 KB |
036.txt | AC | 143 ms | 10240 KB |
037.txt | AC | 141 ms | 9984 KB |
038.txt | AC | 141 ms | 10240 KB |
039.txt | AC | 124 ms | 9472 KB |
040.txt | AC | 369 ms | 26732 KB |
041.txt | AC | 456 ms | 30196 KB |
042.txt | AC | 465 ms | 29932 KB |
043.txt | AC | 457 ms | 30196 KB |
044.txt | AC | 97 ms | 10496 KB |
045.txt | AC | 102 ms | 10496 KB |
046.txt | AC | 99 ms | 10496 KB |
047.txt | AC | 98 ms | 10496 KB |
048.txt | AC | 97 ms | 10496 KB |
049.txt | AC | 3 ms | 4352 KB |
example0.txt | AC | 3 ms | 4352 KB |
example1.txt | AC | 3 ms | 4352 KB |
example2.txt | AC | 3 ms | 4352 KB |
example3.txt | AC | 3 ms | 4352 KB |