답안 #387053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
387053 2021-04-07T21:39:05 Z ogibogi2004 Worst Reporter 4 (JOI21_worst_reporter4) C++14
14 / 100
2000 ms 59884 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)
		{
			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--;
		int 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()
{
	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;
}
# 결과 실행 시간 메모리 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 5 ms 5100 KB Output is correct
5 Correct 12 ms 5740 KB Output is correct
6 Correct 10 ms 5228 KB Output is correct
7 Correct 8 ms 5228 KB Output is correct
8 Correct 12 ms 5740 KB Output is correct
9 Correct 9 ms 5228 KB Output is correct
10 Correct 8 ms 5228 KB Output is correct
11 Correct 7 ms 5228 KB Output is correct
12 Correct 129 ms 6892 KB Output is correct
13 Correct 8 ms 6380 KB Output is correct
14 Correct 95 ms 6764 KB Output is correct
15 Correct 17 ms 5868 KB Output is correct
16 Correct 15 ms 5868 KB Output is correct
17 Correct 10 ms 5356 KB Output is correct
18 Correct 6 ms 5228 KB Output is correct
19 Correct 14 ms 6252 KB Output is correct
20 Correct 8 ms 5740 KB Output is correct
21 Correct 7 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 13 ms 6252 KB Output is correct
25 Correct 7 ms 5740 KB Output is correct
26 Correct 11 ms 6892 KB Output is correct
27 Correct 158 ms 6124 KB Output is correct
28 Correct 296 ms 6380 KB Output is correct
29 Correct 275 ms 6764 KB Output is correct
30 Correct 14 ms 6764 KB Output is correct
31 Correct 14 ms 6764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 5740 KB Output is correct
2 Correct 555 ms 36040 KB Output is correct
3 Correct 350 ms 12780 KB Output is correct
4 Correct 559 ms 32184 KB Output is correct
5 Correct 352 ms 12908 KB Output is correct
6 Correct 233 ms 12260 KB Output is correct
7 Correct 170 ms 12140 KB Output is correct
8 Execution timed out 2086 ms 59884 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 5 ms 5100 KB Output is correct
5 Correct 12 ms 5740 KB Output is correct
6 Correct 10 ms 5228 KB Output is correct
7 Correct 8 ms 5228 KB Output is correct
8 Correct 12 ms 5740 KB Output is correct
9 Correct 9 ms 5228 KB Output is correct
10 Correct 8 ms 5228 KB Output is correct
11 Correct 7 ms 5228 KB Output is correct
12 Correct 129 ms 6892 KB Output is correct
13 Correct 8 ms 6380 KB Output is correct
14 Correct 95 ms 6764 KB Output is correct
15 Correct 17 ms 5868 KB Output is correct
16 Correct 15 ms 5868 KB Output is correct
17 Correct 10 ms 5356 KB Output is correct
18 Correct 6 ms 5228 KB Output is correct
19 Correct 14 ms 6252 KB Output is correct
20 Correct 8 ms 5740 KB Output is correct
21 Correct 7 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 13 ms 6252 KB Output is correct
25 Correct 7 ms 5740 KB Output is correct
26 Correct 11 ms 6892 KB Output is correct
27 Correct 158 ms 6124 KB Output is correct
28 Correct 296 ms 6380 KB Output is correct
29 Correct 275 ms 6764 KB Output is correct
30 Correct 14 ms 6764 KB Output is correct
31 Correct 14 ms 6764 KB Output is correct
32 Correct 12 ms 5740 KB Output is correct
33 Correct 555 ms 36040 KB Output is correct
34 Correct 350 ms 12780 KB Output is correct
35 Correct 559 ms 32184 KB Output is correct
36 Correct 352 ms 12908 KB Output is correct
37 Correct 233 ms 12260 KB Output is correct
38 Correct 170 ms 12140 KB Output is correct
39 Execution timed out 2086 ms 59884 KB Time limit exceeded
40 Halted 0 ms 0 KB -