Submission #1825050
Source Code Expand
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <utility> #define FR first #define SE second #define last last2 using namespace std; typedef long long ll; typedef pair<ll,ll> pr; vector <pr> a[1<<18]; pr p[1<<18],q[1<<18]; int ch[1<<18][2]; ll v[1<<18],d[1<<18]; void dfs(int x,int dep) { a[x].clear(); int ls=ch[x][0],rs=ch[x][1]; if (ls) { d[ls]=d[x]+v[ls];d[rs]=d[x]+v[rs]; dfs(ls,dep); dfs(rs,dep); int s1=0,s2=0; if (a[rs].size()) { int r=0; for(int i=0;i<a[ls].size();i++) { while (r<a[rs].size()-1&&a[rs][r+1].FR+a[ls][i].SE-2*d[x]<=dep) r++; if (a[rs][r].FR+a[ls][i].SE-2*d[x]<=dep) p[++s1]=pr(a[ls][i].FR,a[rs][r].SE); } } if (a[ls].size()) { int r=0; for(int i=0;i<a[rs].size();i++) { while (r<a[ls].size()-1&&a[ls][r+1].FR+a[rs][i].SE-2*d[x]<=dep) r++; if (a[ls][r].FR+a[rs][i].SE-2*d[x]<=dep) q[++s2]=pr(a[rs][i].FR,a[ls][r].SE); } } int l=1,r=1; ll last=(ll)(1e17); for(int i=1;i<=s1+s2;i++) if (l<=s1&&(r>s2||p[l]<q[r])) { if (p[l].SE<last) { a[x].push_back(p[l]); last=p[l].SE; } l++; } else { if (q[r].SE<last) { a[x].push_back(q[r]); last=q[r].SE; } r++; } } else a[x].push_back(pr(d[x],d[x])); } int main() { int n; scanf("%d",&n); for(int i=2;i<=n;i++) { int x,y; scanf("%d%d",&x,&y); if (!ch[x][0]) ch[x][0]=i; else ch[x][1]=i; v[i]=y; } int l=0,r=1<<30; while (l<r) { int m=((l+r)>>1); dfs(1,m); if (a[1].size()) r=m; else l=m+1; } printf("%d\n",l); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Shik and Travel |
User | mayaohua |
Language | C++14 (GCC 5.4.1) |
Score | 1400 |
Code Size | 1794 Byte |
Status | AC |
Exec Time | 290 ms |
Memory | 38440 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:67:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.cpp:70:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d",&x,&y); ^
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 | 6 ms | 14720 KB |
001.txt | AC | 6 ms | 14720 KB |
002.txt | AC | 6 ms | 14720 KB |
003.txt | AC | 6 ms | 14720 KB |
004.txt | AC | 6 ms | 14720 KB |
005.txt | AC | 6 ms | 14720 KB |
006.txt | AC | 6 ms | 14720 KB |
007.txt | AC | 6 ms | 14720 KB |
008.txt | AC | 6 ms | 14720 KB |
009.txt | AC | 6 ms | 14720 KB |
010.txt | AC | 138 ms | 20864 KB |
011.txt | AC | 138 ms | 20736 KB |
012.txt | AC | 138 ms | 20736 KB |
013.txt | AC | 133 ms | 20736 KB |
014.txt | AC | 138 ms | 20864 KB |
015.txt | AC | 136 ms | 20736 KB |
016.txt | AC | 137 ms | 20736 KB |
017.txt | AC | 135 ms | 20736 KB |
018.txt | AC | 135 ms | 20736 KB |
019.txt | AC | 136 ms | 20736 KB |
020.txt | AC | 136 ms | 20736 KB |
021.txt | AC | 136 ms | 20736 KB |
022.txt | AC | 134 ms | 20736 KB |
023.txt | AC | 139 ms | 20736 KB |
024.txt | AC | 136 ms | 20736 KB |
025.txt | AC | 139 ms | 20864 KB |
026.txt | AC | 124 ms | 20224 KB |
027.txt | AC | 136 ms | 20736 KB |
028.txt | AC | 126 ms | 20224 KB |
029.txt | AC | 126 ms | 20352 KB |
030.txt | AC | 127 ms | 20736 KB |
031.txt | AC | 134 ms | 20736 KB |
032.txt | AC | 138 ms | 20736 KB |
033.txt | AC | 126 ms | 20736 KB |
034.txt | AC | 126 ms | 20736 KB |
035.txt | AC | 137 ms | 20736 KB |
036.txt | AC | 128 ms | 20736 KB |
037.txt | AC | 130 ms | 20608 KB |
038.txt | AC | 127 ms | 20736 KB |
039.txt | AC | 102 ms | 19712 KB |
040.txt | AC | 221 ms | 38440 KB |
041.txt | AC | 290 ms | 38440 KB |
042.txt | AC | 287 ms | 38440 KB |
043.txt | AC | 269 ms | 38440 KB |
044.txt | AC | 102 ms | 28928 KB |
045.txt | AC | 113 ms | 24832 KB |
046.txt | AC | 113 ms | 25984 KB |
047.txt | AC | 114 ms | 25216 KB |
048.txt | AC | 116 ms | 27648 KB |
049.txt | AC | 4 ms | 14592 KB |
example0.txt | AC | 4 ms | 14592 KB |
example1.txt | AC | 4 ms | 14592 KB |
example2.txt | AC | 4 ms | 14592 KB |
example3.txt | AC | 5 ms | 14592 KB |