Submission #833931

# Submission time Handle Problem Language Result Execution time Memory
833931 2023-08-22T09:34:05 Z MODDI Magic Tree (CEOI19_magictree) C++14
13 / 100
55 ms 19052 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
int n, m, k;
vi G[100100];
vector<pll> fruits;
map<int, int> dp[100100];
void dfs(int node, int p){
//	cout<<"AT: "<<node<<endl;
	for(auto next : G[node]){
		if(next !=p){
			dfs(next, node);
			if(dp[node].size() < dp[next].size()) swap(dp[node], dp[next]);
			for(auto t : dp[next])	dp[node][t.first] += t.second;
		}
	}
	if(fruits[node].first != -1){
		ll hold = fruits[node].second;
		while(hold > 1	){
			auto rem = dp[node].upper_bound(fruits[node].first);
			if(rem == dp[node].end())	break;
			if(rem->second <= hold){
				hold -= rem->second;
				dp[node].erase(rem);
			}
			else{
				rem->second -= hold;
				break;
			}
		}
		
		dp[node][fruits[node].first] += fruits[node].second;
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m>>k;
	for(int i = 2; i <= n; i++){
		int a;
		cin>>a;
		G[a-1].pb(i-1);
		G[i-1].pb(a-1);
	}
	fruits.resize(n);
	for(int i = 0; i < n; i++)
		fruits[i] = mp(-1, -1);
	for(int i = 0; i < m; i++){
		int node, day, add;
		cin>>node>>day>>add;
		node--;
		fruits[node] = mp(day, add);
	}
	ll ans = 0;
	dfs(0, -1);
//	cout<<dp[0].size()<<endl;
	for(auto t : dp[0])	ans += t.second;
	
	cout<<ans<<endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 55 ms 19052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 7512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 16844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8528 KB Output is correct
2 Correct 30 ms 12828 KB Output is correct
3 Correct 28 ms 12876 KB Output is correct
4 Correct 26 ms 12884 KB Output is correct
5 Correct 14 ms 12748 KB Output is correct
6 Correct 32 ms 15372 KB Output is correct
7 Correct 34 ms 17812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7252 KB Output isn't correct
2 Halted 0 ms 0 KB -