Submission #387049

# Submission time Handle Problem Language Result Execution time Memory
387049 2021-04-07T21:35:28 Z ogibogi2004 Worst Reporter 4 (JOI21_worst_reporter4) C++14
14 / 100
2000 ms 65228 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAXN=2e5+6;
ll n;
vector<ll>g[MAXN];
ll a[MAXN],h[MAXN],c[MAXN],subtree[MAXN];
void dfs1(ll u,ll p)
{
	subtree[u]=1;
	for(auto xd:g[u])
	{
		if(xd==p)continue;
		dfs1(xd,u);
		subtree[u]+=subtree[xd];
	}
}
void dfs(ll u,ll p,map<ll,ll> &mp)
{
	ll 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<ll,ll> tmp;
		dfs(xd,u,tmp);
		for(auto it:tmp)
		{
			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]);
	while(mp[h[u]]<0)
	{
		it--;
		ll t=(*it).first;
		if(mp[t]+mp[h[u]]>=0)
		{
			mp[t]+=mp[h[u]];
			mp[h[u]]=0;
		}
		else
		{
			mp[h[u]]+=mp[t];
			mp[t]=0;
		}
	}
}
int main()
{
	cin>>n;
	for(ll 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<ll,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 5 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 5 ms 5100 KB Output is correct
5 Correct 16 ms 5868 KB Output is correct
6 Correct 13 ms 5484 KB Output is correct
7 Correct 12 ms 5356 KB Output is correct
8 Correct 18 ms 5996 KB Output is correct
9 Correct 14 ms 5484 KB Output is correct
10 Correct 12 ms 5484 KB Output is correct
11 Correct 11 ms 5356 KB Output is correct
12 Correct 140 ms 7148 KB Output is correct
13 Correct 12 ms 6508 KB Output is correct
14 Correct 98 ms 6892 KB Output is correct
15 Correct 25 ms 6124 KB Output is correct
16 Correct 21 ms 5996 KB Output is correct
17 Correct 14 ms 5484 KB Output is correct
18 Correct 10 ms 5356 KB Output is correct
19 Correct 18 ms 6380 KB Output is correct
20 Correct 12 ms 5868 KB Output is correct
21 Correct 11 ms 5868 KB Output is correct
22 Correct 11 ms 5612 KB Output is correct
23 Correct 10 ms 5356 KB Output is correct
24 Correct 17 ms 6380 KB Output is correct
25 Correct 11 ms 5996 KB Output is correct
26 Correct 19 ms 7148 KB Output is correct
27 Correct 169 ms 6252 KB Output is correct
28 Correct 309 ms 6636 KB Output is correct
29 Correct 280 ms 6848 KB Output is correct
30 Correct 19 ms 6892 KB Output is correct
31 Correct 18 ms 6892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 5868 KB Output is correct
2 Correct 729 ms 42384 KB Output is correct
3 Correct 517 ms 19024 KB Output is correct
4 Correct 740 ms 38308 KB Output is correct
5 Correct 530 ms 19144 KB Output is correct
6 Correct 390 ms 18540 KB Output is correct
7 Correct 347 ms 18412 KB Output is correct
8 Execution timed out 2058 ms 65228 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 5 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 5 ms 5100 KB Output is correct
5 Correct 16 ms 5868 KB Output is correct
6 Correct 13 ms 5484 KB Output is correct
7 Correct 12 ms 5356 KB Output is correct
8 Correct 18 ms 5996 KB Output is correct
9 Correct 14 ms 5484 KB Output is correct
10 Correct 12 ms 5484 KB Output is correct
11 Correct 11 ms 5356 KB Output is correct
12 Correct 140 ms 7148 KB Output is correct
13 Correct 12 ms 6508 KB Output is correct
14 Correct 98 ms 6892 KB Output is correct
15 Correct 25 ms 6124 KB Output is correct
16 Correct 21 ms 5996 KB Output is correct
17 Correct 14 ms 5484 KB Output is correct
18 Correct 10 ms 5356 KB Output is correct
19 Correct 18 ms 6380 KB Output is correct
20 Correct 12 ms 5868 KB Output is correct
21 Correct 11 ms 5868 KB Output is correct
22 Correct 11 ms 5612 KB Output is correct
23 Correct 10 ms 5356 KB Output is correct
24 Correct 17 ms 6380 KB Output is correct
25 Correct 11 ms 5996 KB Output is correct
26 Correct 19 ms 7148 KB Output is correct
27 Correct 169 ms 6252 KB Output is correct
28 Correct 309 ms 6636 KB Output is correct
29 Correct 280 ms 6848 KB Output is correct
30 Correct 19 ms 6892 KB Output is correct
31 Correct 18 ms 6892 KB Output is correct
32 Correct 16 ms 5868 KB Output is correct
33 Correct 729 ms 42384 KB Output is correct
34 Correct 517 ms 19024 KB Output is correct
35 Correct 740 ms 38308 KB Output is correct
36 Correct 530 ms 19144 KB Output is correct
37 Correct 390 ms 18540 KB Output is correct
38 Correct 347 ms 18412 KB Output is correct
39 Execution timed out 2058 ms 65228 KB Time limit exceeded
40 Halted 0 ms 0 KB -