Submission #1693171
Source Code Expand
#include<bits/stdc++.h> using namespace std; #define LL long long #define X first #define Y second const int maxn=131072+233; int n,fa[maxn],lc[maxn],rc[maxn],w[maxn]; LL mid; vector<pair<LL,LL> > S[maxn],t1,t2; void dfs(int u) { if (!lc[u]) { S[u].push_back(make_pair(w[u],w[u])); return; } dfs(lc[u]); dfs(rc[u]); int i,j=-1,m=S[rc[u]].size()-1; LL last; t1.clear(); t2.clear(); for (i=0;i<(int)S[lc[u]].size();i++) { bool flag=0; while (j<m&&S[lc[u]][i].Y+S[rc[u]][j+1].X<=mid) j++,flag=1; if (flag) { t1.push_back(make_pair(S[lc[u]][i].X+w[u],S[rc[u]][j].Y+w[u])); t2.push_back(make_pair(S[rc[u]][j].Y+w[u],S[lc[u]][i].X+w[u])); } } for (last=1e18,m=t1.size(),i=0,j=m-1;i<m||j>=0;) { bool flag=i==m?0:j==-1?1:t1[i]<t2[j]; pair<LL,LL> pr=flag?t1[i++]:t2[j--]; if (last>pr.Y) last=pr.Y,S[u].push_back(pr); } } int main() { #ifdef h10 freopen("E.in","r",stdin); freopen("E.out","w",stdout); #endif int i; LL L=0,R=0; scanf("%d",&n); for (i=2;i<=n;i++) { scanf("%d%d",&fa[i],&w[i]); if (lc[fa[i]]) rc[fa[i]]=i; else lc[fa[i]]=i; R+=w[i]; } while (L<=R) { mid=(L+R)>>1; for (i=1;i<=n;i++) S[i].clear(); dfs(1); S[1].size()?R=mid-1:L=mid+1; } printf("%lld\n",L); }
Submission Info
Submission Time | |
---|---|
Task | E - Shik and Travel |
User | h10 |
Language | C++14 (GCC 5.4.1) |
Score | 1400 |
Code Size | 1302 Byte |
Status | AC |
Exec Time | 292 ms |
Memory | 29144 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:51:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.cpp:54:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d",&fa[i],&w[i]); ^
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 | 4 ms | 4480 KB |
001.txt | AC | 4 ms | 4480 KB |
002.txt | AC | 4 ms | 4480 KB |
003.txt | AC | 4 ms | 4480 KB |
004.txt | AC | 4 ms | 4480 KB |
005.txt | AC | 4 ms | 4480 KB |
006.txt | AC | 4 ms | 4480 KB |
007.txt | AC | 4 ms | 4480 KB |
008.txt | AC | 4 ms | 4480 KB |
009.txt | AC | 4 ms | 4480 KB |
010.txt | AC | 131 ms | 10624 KB |
011.txt | AC | 129 ms | 10624 KB |
012.txt | AC | 133 ms | 10624 KB |
013.txt | AC | 138 ms | 10496 KB |
014.txt | AC | 140 ms | 10624 KB |
015.txt | AC | 131 ms | 10496 KB |
016.txt | AC | 132 ms | 10624 KB |
017.txt | AC | 132 ms | 10624 KB |
018.txt | AC | 135 ms | 10624 KB |
019.txt | AC | 144 ms | 10496 KB |
020.txt | AC | 142 ms | 10496 KB |
021.txt | AC | 142 ms | 10496 KB |
022.txt | AC | 141 ms | 10496 KB |
023.txt | AC | 142 ms | 10496 KB |
024.txt | AC | 141 ms | 10496 KB |
025.txt | AC | 142 ms | 10496 KB |
026.txt | AC | 136 ms | 9984 KB |
027.txt | AC | 140 ms | 10496 KB |
028.txt | AC | 136 ms | 9984 KB |
029.txt | AC | 136 ms | 9984 KB |
030.txt | AC | 117 ms | 10240 KB |
031.txt | AC | 124 ms | 10496 KB |
032.txt | AC | 126 ms | 10496 KB |
033.txt | AC | 115 ms | 10240 KB |
034.txt | AC | 115 ms | 10240 KB |
035.txt | AC | 140 ms | 10496 KB |
036.txt | AC | 125 ms | 10240 KB |
037.txt | AC | 133 ms | 10112 KB |
038.txt | AC | 123 ms | 10240 KB |
039.txt | AC | 114 ms | 9472 KB |
040.txt | AC | 232 ms | 29144 KB |
041.txt | AC | 281 ms | 28892 KB |
042.txt | AC | 283 ms | 29144 KB |
043.txt | AC | 292 ms | 29144 KB |
044.txt | AC | 130 ms | 15616 KB |
045.txt | AC | 135 ms | 13056 KB |
046.txt | AC | 136 ms | 13824 KB |
047.txt | AC | 135 ms | 13312 KB |
048.txt | AC | 136 ms | 14848 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 |