Submission #1626759


Source Code Expand

#include<bits/stdc++.h>
const int N=133333;
typedef long long i64;
#define LC lc[ns]
#define RC rc[ns]
int n;
i64 L=0,R=0,M;
struct pos{
	i64 x,y;
}mem[N*40],*mp=mem;
struct node{
	int lc,rc,sz,ap;
	i64 dep;
	pos*as;
	void ac(int x){(lc?rc:lc)=x;}
	void alloc(int n){as=mp,mp+=n;}
	void push(const pos&w){
		if(ap&&as[ap-1].y<=w.y)return;
		as[ap++]=w;
	}
	void mg(node&a,node&b){
		pos*ls=a.as,*rs=b.as;
		int lp=a.ap,rp=b.ap,pp=0;
		i64 lim=M+dep*2;
		ap=0;
		int i,j;
		for(i=0,j=0;i<rp;++i){
			for(;j<lp&&ls[j].x+rs[i].y<=lim;++j);
			if(j)mp[pp++]=(pos){rs[i].x,ls[j-1].y};
		}
		j=0;
		for(i=pp-1;i>=0;--i){
			for(;j<pp&&mp[j].x<mp[i].y;push(mp[j++]));
			push((pos){mp[i].y,mp[i].x});
		}
		for(;j<pp;push(mp[j++]));
	}
}ns[N];
void f1(int x){
	node&w=ns[x];
	if(w.lc){
		w.LC.dep+=w.dep;
		w.RC.dep+=w.dep;
		f1(w.lc);
		f1(w.rc);
		w.sz=w.LC.sz+w.RC.sz;
		if(w.LC.sz<w.RC.sz)std::swap(w.lc,w.rc);
		w.alloc(w.RC.sz*2);
	}else{
		w.sz=1;
		w.alloc(1);
	}
}
void f2(int x){
	node&w=ns[x];
	if(w.lc){
		f2(w.lc);
		f2(w.rc);
		w.mg(w.LC,w.RC);
	}else{
		w.ap=0;
		w.push((pos){w.dep,w.dep});
	}
}
int main(){
	scanf("%d",&n);
	for(int i=2;i<=n;++i){
		int f,d;
		scanf("%d%d",&f,&d);
		ns[i].dep=d;
		ns[f].ac(i);
		R+=d;
	}
	f1(1);
	while(L<R){
		M=L+R>>1;
		f2(1);
		if(ns[1].ap)R=M;
		else L=M+1;
	}
	printf("%lld\n",L);
	return 0;
}

Submission Info

Submission Time
Task E - Shik and Travel
User ccz181078
Language C++14 (GCC 5.4.1)
Score 1400
Code Size 1426 Byte
Status AC
Exec Time 123 ms
Memory 22912 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:66:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
./Main.cpp:69:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&f,&d);
                      ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1400 / 1400
Status
AC × 4
AC × 54
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 3 ms 2304 KB
001.txt AC 3 ms 2304 KB
002.txt AC 3 ms 2304 KB
003.txt AC 3 ms 2304 KB
004.txt AC 3 ms 2304 KB
005.txt AC 3 ms 2304 KB
006.txt AC 3 ms 2304 KB
007.txt AC 3 ms 2304 KB
008.txt AC 3 ms 2304 KB
009.txt AC 3 ms 2304 KB
010.txt AC 99 ms 18688 KB
011.txt AC 100 ms 18688 KB
012.txt AC 101 ms 18688 KB
013.txt AC 101 ms 18688 KB
014.txt AC 105 ms 18688 KB
015.txt AC 102 ms 18688 KB
016.txt AC 106 ms 18688 KB
017.txt AC 99 ms 18688 KB
018.txt AC 103 ms 18688 KB
019.txt AC 107 ms 18688 KB
020.txt AC 107 ms 18688 KB
021.txt AC 106 ms 18688 KB
022.txt AC 120 ms 18688 KB
023.txt AC 111 ms 18816 KB
024.txt AC 111 ms 18688 KB
025.txt AC 114 ms 18688 KB
026.txt AC 99 ms 18688 KB
027.txt AC 108 ms 18688 KB
028.txt AC 98 ms 18688 KB
029.txt AC 100 ms 18688 KB
030.txt AC 96 ms 22912 KB
031.txt AC 108 ms 22784 KB
032.txt AC 111 ms 22784 KB
033.txt AC 96 ms 22784 KB
034.txt AC 94 ms 22784 KB
035.txt AC 123 ms 22784 KB
036.txt AC 104 ms 22784 KB
037.txt AC 105 ms 22784 KB
038.txt AC 103 ms 22784 KB
039.txt AC 93 ms 22784 KB
040.txt AC 74 ms 22784 KB
041.txt AC 94 ms 22784 KB
042.txt AC 99 ms 22784 KB
043.txt AC 104 ms 22784 KB
044.txt AC 97 ms 12544 KB
045.txt AC 98 ms 12544 KB
046.txt AC 98 ms 11008 KB
047.txt AC 97 ms 10624 KB
048.txt AC 98 ms 11904 KB
049.txt AC 2 ms 2304 KB
example0.txt AC 2 ms 2304 KB
example1.txt AC 2 ms 2304 KB
example2.txt AC 2 ms 2304 KB
example3.txt AC 1 ms 256 KB