Submission #933026

# Submission time Handle Problem Language Result Execution time Memory
933026 2024-02-24T21:53:22 Z Cyber_Wolf Magic Tree (CEOI19_magictree) C++17
3 / 100
81 ms 17232 KB
#include <bits/stdc++.h>

using namespace std;

#define lg long long
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const lg N = 1e5+5;

lg n, m, k;
lg v[N], d[N];
vector<lg> adj[N];
map<lg, lg> mp2;

lg solve(lg src)
{
	map<lg, lg> mp;
	mp[0] = 0; 
	lg ans = 0;
	for(auto it : adj[src])
	{
		ans += solve(it);
		if(mp.size() < mp2.size())
		{
			swap(mp, mp2);
		}
		for(auto [it, fr] : mp2)
		{
			mp[it] += fr;
		}
	}
	if(d[src])
	{
		auto it = mp.lower_bound(d[src]);
		if(it != mp.end() && it->first == d[src])
		{
			it->second += v[src];
		}
		else{
			it--;
			mp[d[src]] = v[src];
		}
		while(mp.size() > 1 && ((--mp.end())->second) < v[src])	mp.erase(--mp.end());
		if(((--mp.end())->first) == d[src])	ans += mp[d[src]];
	} 
	swap(mp, mp2);
	return ans;
}

int main()
{
	fastio;
	cin >> n >> m >> k;
	for(int i = 2; i <= n; i++)
	{
		lg p;
		cin >> p;
		adj[p].push_back(i);
	}
	for(int i = 1; i <= m; i++)
	{
		lg node, day, score;
		cin >> node >> day >> score;
		d[node] = day;
		v[node] = score;
	}
	cout << solve(1) << '\n';

    return 0;
}


/*
dp[src][max] = max(dp[par][v[i]]+w[i], dp[src][max-1])
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Incorrect 1 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 8980 KB Output is correct
2 Correct 34 ms 17232 KB Output is correct
3 Correct 81 ms 12552 KB Output is correct
4 Correct 50 ms 10712 KB Output is correct
5 Correct 60 ms 13308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 8284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Incorrect 1 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Incorrect 1 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Incorrect 1 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -