Submission #387059

# Submission time Handle Problem Language Result Execution time Memory
387059 2021-04-07T21:44:52 Z ogibogi2004 Worst Reporter 4 (JOI21_worst_reporter4) C++14
79 / 100
373 ms 81132 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=2e5+6;
int n;
vector<int>g[MAXN];
ll c[MAXN];
int a[MAXN],h[MAXN],subtree[MAXN];
void dfs1(int u,int p)
{
	subtree[u]=1;
	for(auto xd:g[u])
	{
		if(xd==p)continue;
		dfs1(xd,u);
		subtree[u]+=subtree[xd];
	}
}
void dfs(int u,int p,map<int,ll> &mp)
{
	int bc=-1,maxst=-1;
	for(auto xd:g[u])
	{
		if(xd==p)continue;
		if(subtree[xd]>maxst)
		{
			maxst=subtree[xd];
			bc=xd;
		}
	}
	if(bc==-1)
	{
		mp[h[u]+1]=c[u];
		return;
	}
	dfs(bc,u,mp);
	for(auto xd:g[u])
	{
		if(xd==p||xd==bc)continue;
		map<int,ll> tmp;
		dfs(xd,u,tmp);
		for(auto it:tmp)
		{
			if(it.second!=0)mp[it.first]+=it.second;
		}
	}
	mp[h[u]+1]+=c[u];
	mp[0]+=c[u];
	mp[h[u]]-=c[u];
	auto it=mp.lower_bound(h[u]);
	int d=mp[h[u]];
	auto it1=it;
	it--;
	while(d<0)
	{
		int t=(*it).first;
		if((*it).second+d>=0)
		{
			mp[t]+=d;
			d=0;
		}
		else
		{
			d+=(*it).second;
			it1=it;
			it--;mp.erase(it1);
		}
	}
	mp[h[u]]=d;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i]>>h[i]>>c[i];
		if(i!=1)g[a[i]].push_back(i);
	}
	dfs1(1,0);
	map<int,ll>mp;
	dfs(1,0,mp);
	cout<<mp[0]<<endl;
return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 9 ms 5484 KB Output is correct
6 Correct 8 ms 5228 KB Output is correct
7 Correct 7 ms 5228 KB Output is correct
8 Correct 9 ms 5484 KB Output is correct
9 Correct 8 ms 5228 KB Output is correct
10 Correct 7 ms 5228 KB Output is correct
11 Correct 7 ms 5228 KB Output is correct
12 Correct 9 ms 6252 KB Output is correct
13 Correct 8 ms 6252 KB Output is correct
14 Correct 9 ms 5868 KB Output is correct
15 Correct 9 ms 5868 KB Output is correct
16 Correct 10 ms 5612 KB Output is correct
17 Correct 8 ms 5228 KB Output is correct
18 Correct 6 ms 5228 KB Output is correct
19 Correct 9 ms 5996 KB Output is correct
20 Correct 7 ms 5740 KB Output is correct
21 Correct 9 ms 5740 KB Output is correct
22 Correct 7 ms 5484 KB Output is correct
23 Correct 6 ms 5228 KB Output is correct
24 Correct 9 ms 6012 KB Output is correct
25 Correct 7 ms 5740 KB Output is correct
26 Correct 10 ms 6892 KB Output is correct
27 Correct 8 ms 5996 KB Output is correct
28 Correct 9 ms 6252 KB Output is correct
29 Correct 9 ms 6636 KB Output is correct
30 Correct 11 ms 6508 KB Output is correct
31 Correct 10 ms 6508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 5484 KB Output is correct
2 Correct 360 ms 24684 KB Output is correct
3 Correct 275 ms 12652 KB Output is correct
4 Correct 373 ms 22636 KB Output is correct
5 Correct 274 ms 12460 KB Output is correct
6 Correct 232 ms 12396 KB Output is correct
7 Correct 165 ms 12268 KB Output is correct
8 Correct 239 ms 53100 KB Output is correct
9 Correct 225 ms 56300 KB Output is correct
10 Correct 132 ms 56044 KB Output is correct
11 Correct 226 ms 37632 KB Output is correct
12 Correct 239 ms 37612 KB Output is correct
13 Correct 332 ms 27828 KB Output is correct
14 Correct 251 ms 15852 KB Output is correct
15 Correct 102 ms 15468 KB Output is correct
16 Correct 330 ms 44596 KB Output is correct
17 Correct 174 ms 34284 KB Output is correct
18 Correct 113 ms 34156 KB Output is correct
19 Correct 225 ms 25544 KB Output is correct
20 Correct 94 ms 13160 KB Output is correct
21 Correct 342 ms 46316 KB Output is correct
22 Correct 156 ms 34660 KB Output is correct
23 Correct 324 ms 81132 KB Output is correct
24 Correct 261 ms 50048 KB Output is correct
25 Correct 258 ms 64364 KB Output is correct
26 Correct 258 ms 70892 KB Output is correct
27 Correct 292 ms 68588 KB Output is correct
28 Correct 290 ms 68716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 9 ms 5484 KB Output is correct
6 Correct 8 ms 5228 KB Output is correct
7 Correct 7 ms 5228 KB Output is correct
8 Correct 9 ms 5484 KB Output is correct
9 Correct 8 ms 5228 KB Output is correct
10 Correct 7 ms 5228 KB Output is correct
11 Correct 7 ms 5228 KB Output is correct
12 Correct 9 ms 6252 KB Output is correct
13 Correct 8 ms 6252 KB Output is correct
14 Correct 9 ms 5868 KB Output is correct
15 Correct 9 ms 5868 KB Output is correct
16 Correct 10 ms 5612 KB Output is correct
17 Correct 8 ms 5228 KB Output is correct
18 Correct 6 ms 5228 KB Output is correct
19 Correct 9 ms 5996 KB Output is correct
20 Correct 7 ms 5740 KB Output is correct
21 Correct 9 ms 5740 KB Output is correct
22 Correct 7 ms 5484 KB Output is correct
23 Correct 6 ms 5228 KB Output is correct
24 Correct 9 ms 6012 KB Output is correct
25 Correct 7 ms 5740 KB Output is correct
26 Correct 10 ms 6892 KB Output is correct
27 Correct 8 ms 5996 KB Output is correct
28 Correct 9 ms 6252 KB Output is correct
29 Correct 9 ms 6636 KB Output is correct
30 Correct 11 ms 6508 KB Output is correct
31 Correct 10 ms 6508 KB Output is correct
32 Correct 10 ms 5484 KB Output is correct
33 Correct 360 ms 24684 KB Output is correct
34 Correct 275 ms 12652 KB Output is correct
35 Correct 373 ms 22636 KB Output is correct
36 Correct 274 ms 12460 KB Output is correct
37 Correct 232 ms 12396 KB Output is correct
38 Correct 165 ms 12268 KB Output is correct
39 Correct 239 ms 53100 KB Output is correct
40 Correct 225 ms 56300 KB Output is correct
41 Correct 132 ms 56044 KB Output is correct
42 Correct 226 ms 37632 KB Output is correct
43 Correct 239 ms 37612 KB Output is correct
44 Correct 332 ms 27828 KB Output is correct
45 Correct 251 ms 15852 KB Output is correct
46 Correct 102 ms 15468 KB Output is correct
47 Correct 330 ms 44596 KB Output is correct
48 Correct 174 ms 34284 KB Output is correct
49 Correct 113 ms 34156 KB Output is correct
50 Correct 225 ms 25544 KB Output is correct
51 Correct 94 ms 13160 KB Output is correct
52 Correct 342 ms 46316 KB Output is correct
53 Correct 156 ms 34660 KB Output is correct
54 Correct 324 ms 81132 KB Output is correct
55 Correct 261 ms 50048 KB Output is correct
56 Correct 258 ms 64364 KB Output is correct
57 Correct 258 ms 70892 KB Output is correct
58 Correct 292 ms 68588 KB Output is correct
59 Correct 290 ms 68716 KB Output is correct
60 Correct 4 ms 5100 KB Output is correct
61 Incorrect 4 ms 5100 KB Output isn't correct
62 Halted 0 ms 0 KB -