Submission #1771481
Source Code Expand
#include<bits/stdc++.h> #define ft first #define sd second #define pd push_back #define mk make_pair #define ll long long #define N 140005 using namespace std; int n; vector<int>v[N],q[N]; ll now; vector<pair<ll,ll> >s[N]; map<ll,int>mp; bool fl; void dfs(int x) { if(!v[x].size()) { s[x].push_back(mk(0,0)); return ; } dfs(v[x][0]);dfs(v[x][1]); if(!s[v[x][0]].size()||!s[v[x][1]].size())return ; for(int t=0;t<=1;t++) { int ls=q[x][0],rs=q[x][1]; int l=v[x][0],r=v[x][1]; int p=-1; for(int i=0;i<s[l].size();i++) { bool flag=0; while(p+1<s[r].size()) { if(-s[l][i].sd+s[r][p+1].ft+ls+rs<=now)p++,flag=1; else break; } //if(x==1)cout<<p<<endl; if(flag) { s[x].pd(mk(s[l][i].ft+ls,s[r][p].sd-rs)); } } swap(v[x][0],v[x][1]);swap(q[x][0],q[x][1]); } sort(s[x].begin(),s[x].end()); if(!s[x].size())fl=1; } bool pan(ll x) { for(int i=1;i<=n;i++)s[i].clear(); now=x; fl=0; dfs(1); return (fl^1); } int main() { scanf("%d",&n); for(int i=2;i<=n;i++) { int t1,t2;scanf("%d%d",&t1,&t2); v[t1].push_back(i);q[t1].push_back(t2); } ll l=0,r=1e10; while(l<r) { ll mid=(l+r)>>1; if(pan(mid))r=mid; else l=mid+1; } printf("%lld\n",l); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Shik and Travel |
User | SD_le |
Language | C++14 (GCC 5.4.1) |
Score | 1400 |
Code Size | 1474 Byte |
Status | AC |
Exec Time | 652 ms |
Memory | 36600 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:60:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.cpp:63:40: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] int t1,t2;scanf("%d%d",&t1,&t2); ^
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 | 9 ms | 10240 KB |
001.txt | AC | 8 ms | 10240 KB |
002.txt | AC | 9 ms | 10240 KB |
003.txt | AC | 9 ms | 10240 KB |
004.txt | AC | 9 ms | 10240 KB |
005.txt | AC | 9 ms | 10240 KB |
006.txt | AC | 9 ms | 10240 KB |
007.txt | AC | 9 ms | 10240 KB |
008.txt | AC | 9 ms | 10240 KB |
009.txt | AC | 9 ms | 10240 KB |
010.txt | AC | 312 ms | 19328 KB |
011.txt | AC | 343 ms | 19456 KB |
012.txt | AC | 357 ms | 19328 KB |
013.txt | AC | 333 ms | 19328 KB |
014.txt | AC | 374 ms | 19456 KB |
015.txt | AC | 379 ms | 19328 KB |
016.txt | AC | 305 ms | 19328 KB |
017.txt | AC | 368 ms | 19328 KB |
018.txt | AC | 325 ms | 19456 KB |
019.txt | AC | 423 ms | 19328 KB |
020.txt | AC | 362 ms | 19456 KB |
021.txt | AC | 352 ms | 19328 KB |
022.txt | AC | 376 ms | 19328 KB |
023.txt | AC | 457 ms | 19328 KB |
024.txt | AC | 356 ms | 19328 KB |
025.txt | AC | 338 ms | 21376 KB |
026.txt | AC | 343 ms | 19328 KB |
027.txt | AC | 351 ms | 19328 KB |
028.txt | AC | 373 ms | 19328 KB |
029.txt | AC | 359 ms | 19328 KB |
030.txt | AC | 199 ms | 19328 KB |
031.txt | AC | 355 ms | 19328 KB |
032.txt | AC | 349 ms | 19328 KB |
033.txt | AC | 196 ms | 19328 KB |
034.txt | AC | 203 ms | 19328 KB |
035.txt | AC | 373 ms | 19328 KB |
036.txt | AC | 195 ms | 19328 KB |
037.txt | AC | 200 ms | 19328 KB |
038.txt | AC | 194 ms | 19328 KB |
039.txt | AC | 384 ms | 19328 KB |
040.txt | AC | 394 ms | 36600 KB |
041.txt | AC | 600 ms | 36600 KB |
042.txt | AC | 619 ms | 36600 KB |
043.txt | AC | 652 ms | 36600 KB |
044.txt | AC | 231 ms | 29568 KB |
045.txt | AC | 227 ms | 24448 KB |
046.txt | AC | 226 ms | 25984 KB |
047.txt | AC | 228 ms | 24832 KB |
048.txt | AC | 234 ms | 27904 KB |
049.txt | AC | 6 ms | 10112 KB |
example0.txt | AC | 6 ms | 10112 KB |
example1.txt | AC | 6 ms | 10112 KB |
example2.txt | AC | 6 ms | 10112 KB |
example3.txt | AC | 6 ms | 10112 KB |