Submission #1839643
Source Code Expand
#include<bits/stdc++.h> #define N ((1<<17)+3) using namespace std; vector<int> son[N]; vector<pair<int,int> > dp[N]; int mid,dis[N]; vector<pair<int,int> > temp; bool DFS(int u,int fr){ dp[u].clear(); for(int i:son[u]) if(!DFS(i,u)) return false; if(son[u].size()==0){ dp[u].push_back(make_pair(0,0)); }else{ temp.clear(); int l=son[u][0],r=son[u][1],limit=mid-dis[l]-dis[r]; if(dp[l].size()>dp[r].size()) swap(l,r); for(int i=0,p=0;i<dp[l].size()&&p<dp[r].size();i++){ while(p+1<dp[r].size() && dp[l][i].second+dp[r][p+1].first <= limit) p++; if(dp[l][i].second+dp[r][p].first <= limit) temp.push_back(make_pair( dp[l][i].first+dis[l],dp[r][p].second+dis[r] )); } for(int i=temp.size()-1;i>=0;i--) temp.push_back(make_pair(temp[i].second,temp[i].first)); sort(temp.begin(),temp.end()); for(pair<int,int> x:temp){ if(dp[u].size()==0|| x.second < dp[u][dp[u].size()-1].second ) dp[u].push_back(x); } } return dp[u].size()!=0; } int n,fa[N]; int main(){ scanf("%d",&n); for(int i=2;i<=n;i++) scanf("%d%d",&fa[i],&dis[i]),son[fa[i]].push_back(i); int l=-1,r=2e9;//(] while(l+1<r){ mid=(l+r)>>1; if(!DFS(1,0)) l=mid; else r=mid; } cout<<r<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Shik and Travel |
User | Wuvin |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1461 Byte |
Status | WA |
Exec Time | 465 ms |
Memory | 23544 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:38:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.cpp:39:79: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] for(int i=2;i<=n;i++) scanf("%d%d",&fa[i],&dis[i]),son[fa[i]].push_back(i); ^
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | 6 ms | 6528 KB |
001.txt | AC | 6 ms | 6528 KB |
002.txt | AC | 6 ms | 6528 KB |
003.txt | AC | 6 ms | 6528 KB |
004.txt | AC | 6 ms | 6528 KB |
005.txt | AC | 6 ms | 6528 KB |
006.txt | AC | 6 ms | 6528 KB |
007.txt | AC | 6 ms | 6528 KB |
008.txt | AC | 6 ms | 6528 KB |
009.txt | AC | 6 ms | 6528 KB |
010.txt | AC | 191 ms | 13568 KB |
011.txt | AC | 209 ms | 13568 KB |
012.txt | AC | 200 ms | 13568 KB |
013.txt | AC | 205 ms | 13568 KB |
014.txt | AC | 190 ms | 13568 KB |
015.txt | AC | 201 ms | 13568 KB |
016.txt | AC | 205 ms | 13568 KB |
017.txt | AC | 202 ms | 13568 KB |
018.txt | AC | 208 ms | 13568 KB |
019.txt | AC | 211 ms | 13568 KB |
020.txt | AC | 212 ms | 13568 KB |
021.txt | AC | 213 ms | 13568 KB |
022.txt | AC | 220 ms | 13568 KB |
023.txt | AC | 212 ms | 13568 KB |
024.txt | AC | 205 ms | 13568 KB |
025.txt | AC | 194 ms | 13568 KB |
026.txt | AC | 192 ms | 13568 KB |
027.txt | AC | 226 ms | 13568 KB |
028.txt | AC | 197 ms | 13568 KB |
029.txt | AC | 183 ms | 13568 KB |
030.txt | AC | 182 ms | 13568 KB |
031.txt | AC | 215 ms | 13568 KB |
032.txt | AC | 212 ms | 13568 KB |
033.txt | AC | 172 ms | 13568 KB |
034.txt | AC | 187 ms | 13568 KB |
035.txt | AC | 215 ms | 13568 KB |
036.txt | AC | 192 ms | 13568 KB |
037.txt | AC | 182 ms | 13568 KB |
038.txt | AC | 190 ms | 13568 KB |
039.txt | AC | 173 ms | 13568 KB |
040.txt | AC | 419 ms | 23544 KB |
041.txt | AC | 464 ms | 23544 KB |
042.txt | AC | 460 ms | 23544 KB |
043.txt | AC | 465 ms | 23544 KB |
044.txt | AC | 151 ms | 22784 KB |
045.txt | WA | 141 ms | 18176 KB |
046.txt | WA | 140 ms | 19456 KB |
047.txt | WA | 140 ms | 18560 KB |
048.txt | WA | 148 ms | 21248 KB |
049.txt | AC | 3 ms | 6400 KB |
example0.txt | AC | 3 ms | 6400 KB |
example1.txt | AC | 3 ms | 6400 KB |
example2.txt | AC | 3 ms | 6400 KB |
example3.txt | AC | 3 ms | 6400 KB |