Submission #287491

# Submission time Handle Problem Language Result Execution time Memory
287491 2020-08-31T18:01:21 Z dlwocks31 Magic Tree (CEOI19_magictree) C++17
58 / 100
344 ms 34296 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MX = 1e5+1;
vector<int> adj[MX];
pair<int, int> fruit[MX];
multiset<pair<int, int>> ms[MX];
void merge(multiset<pair<int, int>>& st, pair<int, int> pr) {
	auto [d, w] = pr;
	auto it = st.lower_bound(make_pair(d+1, -1));
	while(w > 0 && it != st.end()) {
		if(w >= it->second) {
			it = st.erase(it);
			w -= it->second;
		} else {
			st.insert({it->first, it->second - w});
			st.erase(it);
			w = 0;
		}
	}
	st.insert(pr);
}
void dfs(int i, int p) {
	int leaf = 1;
	for(int a: adj[i]) {
		if(a == p) continue;
		leaf = 0;
		dfs(a, i);
	}
	if(leaf) {
		if(fruit[i].first)
			ms[i] = {fruit[i]};
	} else {
		int mx = 0;
		for(int a: adj[i]) {
			if(a == p) continue;
			if(ms[a].size() > ms[mx].size())
				mx = a;
		}
		ms[i] = move(ms[mx]);
		for(int a: adj[i]) {
			if(a == p || a == mx) continue;
			for(auto pr: ms[a]) {
				ms[i].insert(pr);
			}
			ms[a].clear();
		}
		if(fruit[i].first) 
			merge(ms[i], fruit[i]);
	}

}
int32_t main() {
	//ios::sync_with_stdio(0);cin.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	for(int i=2; i<=n; i++) {
		int p;
		cin >> p;
		adj[p].push_back(i);
		adj[i].push_back(p);
	}
	for(int i=0; i<m; i++) {
		int v, d, w;
		cin >> v >> d >> w;
		fruit[v] = {d, w};
	}
	dfs(1, 0);
	int ans = 0;
	for(auto [d, w]: ms[1]) {
		ans += w;
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 5 ms 7296 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 169 ms 16120 KB Output is correct
2 Correct 138 ms 19576 KB Output is correct
3 Correct 344 ms 23180 KB Output is correct
4 Correct 261 ms 20584 KB Output is correct
5 Correct 321 ms 22520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7552 KB Output is correct
2 Correct 6 ms 7552 KB Output is correct
3 Correct 7 ms 7680 KB Output is correct
4 Correct 227 ms 28028 KB Output is correct
5 Correct 259 ms 34296 KB Output is correct
6 Correct 239 ms 28152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 331 ms 20520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 5 ms 7296 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 287 ms 18552 KB Output is correct
11 Correct 266 ms 19064 KB Output is correct
12 Correct 228 ms 21496 KB Output is correct
13 Correct 184 ms 19552 KB Output is correct
14 Correct 211 ms 28024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 8576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 5 ms 7296 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 6 ms 7552 KB Output is correct
11 Correct 6 ms 7552 KB Output is correct
12 Correct 7 ms 7680 KB Output is correct
13 Correct 227 ms 28028 KB Output is correct
14 Correct 259 ms 34296 KB Output is correct
15 Correct 239 ms 28152 KB Output is correct
16 Correct 287 ms 18552 KB Output is correct
17 Correct 266 ms 19064 KB Output is correct
18 Correct 228 ms 21496 KB Output is correct
19 Correct 184 ms 19552 KB Output is correct
20 Correct 211 ms 28024 KB Output is correct
21 Correct 54 ms 9904 KB Output is correct
22 Correct 192 ms 16632 KB Output is correct
23 Correct 198 ms 16504 KB Output is correct
24 Correct 290 ms 19320 KB Output is correct
25 Correct 226 ms 19944 KB Output is correct
26 Correct 274 ms 22392 KB Output is correct
27 Correct 246 ms 21496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 5 ms 7296 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 169 ms 16120 KB Output is correct
11 Correct 138 ms 19576 KB Output is correct
12 Correct 344 ms 23180 KB Output is correct
13 Correct 261 ms 20584 KB Output is correct
14 Correct 321 ms 22520 KB Output is correct
15 Correct 6 ms 7552 KB Output is correct
16 Correct 6 ms 7552 KB Output is correct
17 Correct 7 ms 7680 KB Output is correct
18 Correct 227 ms 28028 KB Output is correct
19 Correct 259 ms 34296 KB Output is correct
20 Correct 239 ms 28152 KB Output is correct
21 Incorrect 331 ms 20520 KB Output isn't correct
22 Halted 0 ms 0 KB -