Submission #834357

# Submission time Handle Problem Language Result Execution time Memory
834357 2023-08-22T13:35:52 Z vqpahmad Magic Tree (CEOI19_magictree) C++14
100 / 100
163 ms 107980 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define endl '\n'
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int mod = 1e9 + 7;
const int N = 1e6 + 15;
const ll inf = 1e12;
vector<int> adj[N];
int d[N], w[N];
map<int,int> mp[N];
int ans = 0;
void dfs(int node){
	for (auto to : adj[node]){
		dfs(to);
		if (sz(mp[to]) > sz(mp[node])){
			swap(mp[to], mp[node]);
		}
		for (auto it : mp[to]){
			mp[node][it.F] += it.S;
		}
	}
	int cur = w[node];
	while (cur){
		auto up = mp[node].upper_bound(d[node]);
		int x = min(cur, up->second);
		cur -= x;
		mp[node][d[node]] += x;
		mp[node][up->first] -= x;
		if (cur >= up->second){
			mp[node].erase(up);
		}
	}
	if (node==1){
		for (auto it : mp[node]){
			if (it.first == inf) {
				break;
			}
			ans += it.S;
		}
	}
	return;
}
int32_t main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	for (int i=1;i<=n;i++) mp[i][inf] = inf;
	for (int i=2;i<=n;i++){
		int u;
		cin >> u;
		adj[u].pb(i);
	}
	for (int i=0;i<m;i++){
		int node;
		cin >> node;
		cin >> d[node] >> w[node];
	}
	dfs(1);
	cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 33 ms 70728 KB Output is correct
2 Correct 32 ms 70740 KB Output is correct
3 Correct 38 ms 70704 KB Output is correct
4 Correct 33 ms 70768 KB Output is correct
5 Correct 32 ms 70740 KB Output is correct
6 Correct 33 ms 70740 KB Output is correct
7 Correct 32 ms 70740 KB Output is correct
8 Correct 32 ms 70740 KB Output is correct
9 Correct 37 ms 70740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 88012 KB Output is correct
2 Correct 74 ms 89452 KB Output is correct
3 Correct 163 ms 107980 KB Output is correct
4 Correct 96 ms 90768 KB Output is correct
5 Correct 145 ms 92876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 70996 KB Output is correct
2 Correct 38 ms 70908 KB Output is correct
3 Correct 32 ms 71064 KB Output is correct
4 Correct 75 ms 95796 KB Output is correct
5 Correct 109 ms 101640 KB Output is correct
6 Correct 99 ms 97660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 84048 KB Output is correct
2 Correct 99 ms 85460 KB Output is correct
3 Correct 78 ms 90032 KB Output is correct
4 Correct 68 ms 86748 KB Output is correct
5 Correct 73 ms 97936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 70728 KB Output is correct
2 Correct 32 ms 70740 KB Output is correct
3 Correct 38 ms 70704 KB Output is correct
4 Correct 33 ms 70768 KB Output is correct
5 Correct 32 ms 70740 KB Output is correct
6 Correct 33 ms 70740 KB Output is correct
7 Correct 32 ms 70740 KB Output is correct
8 Correct 32 ms 70740 KB Output is correct
9 Correct 37 ms 70740 KB Output is correct
10 Correct 104 ms 86988 KB Output is correct
11 Correct 100 ms 87372 KB Output is correct
12 Correct 79 ms 89416 KB Output is correct
13 Correct 65 ms 86080 KB Output is correct
14 Correct 73 ms 97228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 72788 KB Output is correct
2 Correct 63 ms 80644 KB Output is correct
3 Correct 65 ms 80588 KB Output is correct
4 Correct 77 ms 80692 KB Output is correct
5 Correct 46 ms 79424 KB Output is correct
6 Correct 62 ms 83148 KB Output is correct
7 Correct 61 ms 87420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 70728 KB Output is correct
2 Correct 32 ms 70740 KB Output is correct
3 Correct 38 ms 70704 KB Output is correct
4 Correct 33 ms 70768 KB Output is correct
5 Correct 32 ms 70740 KB Output is correct
6 Correct 33 ms 70740 KB Output is correct
7 Correct 32 ms 70740 KB Output is correct
8 Correct 32 ms 70740 KB Output is correct
9 Correct 37 ms 70740 KB Output is correct
10 Correct 33 ms 70996 KB Output is correct
11 Correct 38 ms 70908 KB Output is correct
12 Correct 32 ms 71064 KB Output is correct
13 Correct 75 ms 95796 KB Output is correct
14 Correct 109 ms 101640 KB Output is correct
15 Correct 99 ms 97660 KB Output is correct
16 Correct 104 ms 86988 KB Output is correct
17 Correct 100 ms 87372 KB Output is correct
18 Correct 79 ms 89416 KB Output is correct
19 Correct 65 ms 86080 KB Output is correct
20 Correct 73 ms 97228 KB Output is correct
21 Correct 49 ms 75600 KB Output is correct
22 Correct 103 ms 89424 KB Output is correct
23 Correct 125 ms 92624 KB Output is correct
24 Correct 151 ms 101012 KB Output is correct
25 Correct 95 ms 90108 KB Output is correct
26 Correct 128 ms 92144 KB Output is correct
27 Correct 105 ms 91144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 70728 KB Output is correct
2 Correct 32 ms 70740 KB Output is correct
3 Correct 38 ms 70704 KB Output is correct
4 Correct 33 ms 70768 KB Output is correct
5 Correct 32 ms 70740 KB Output is correct
6 Correct 33 ms 70740 KB Output is correct
7 Correct 32 ms 70740 KB Output is correct
8 Correct 32 ms 70740 KB Output is correct
9 Correct 37 ms 70740 KB Output is correct
10 Correct 91 ms 88012 KB Output is correct
11 Correct 74 ms 89452 KB Output is correct
12 Correct 163 ms 107980 KB Output is correct
13 Correct 96 ms 90768 KB Output is correct
14 Correct 145 ms 92876 KB Output is correct
15 Correct 33 ms 70996 KB Output is correct
16 Correct 38 ms 70908 KB Output is correct
17 Correct 32 ms 71064 KB Output is correct
18 Correct 75 ms 95796 KB Output is correct
19 Correct 109 ms 101640 KB Output is correct
20 Correct 99 ms 97660 KB Output is correct
21 Correct 95 ms 84048 KB Output is correct
22 Correct 99 ms 85460 KB Output is correct
23 Correct 78 ms 90032 KB Output is correct
24 Correct 68 ms 86748 KB Output is correct
25 Correct 73 ms 97936 KB Output is correct
26 Correct 104 ms 86988 KB Output is correct
27 Correct 100 ms 87372 KB Output is correct
28 Correct 79 ms 89416 KB Output is correct
29 Correct 65 ms 86080 KB Output is correct
30 Correct 73 ms 97228 KB Output is correct
31 Correct 38 ms 72788 KB Output is correct
32 Correct 63 ms 80644 KB Output is correct
33 Correct 65 ms 80588 KB Output is correct
34 Correct 77 ms 80692 KB Output is correct
35 Correct 46 ms 79424 KB Output is correct
36 Correct 62 ms 83148 KB Output is correct
37 Correct 61 ms 87420 KB Output is correct
38 Correct 49 ms 75600 KB Output is correct
39 Correct 103 ms 89424 KB Output is correct
40 Correct 125 ms 92624 KB Output is correct
41 Correct 151 ms 101012 KB Output is correct
42 Correct 95 ms 90108 KB Output is correct
43 Correct 128 ms 92144 KB Output is correct
44 Correct 105 ms 91144 KB Output is correct
45 Correct 58 ms 75952 KB Output is correct
46 Correct 107 ms 90548 KB Output is correct
47 Correct 114 ms 93892 KB Output is correct
48 Correct 162 ms 104012 KB Output is correct
49 Correct 95 ms 90724 KB Output is correct
50 Correct 156 ms 93132 KB Output is correct
51 Correct 128 ms 92036 KB Output is correct