Submission #976891

# Submission time Handle Problem Language Result Execution time Memory
976891 2024-05-07T08:36:14 Z batsukh2006 Magic Tree (CEOI19_magictree) C++17
100 / 100
135 ms 38204 KB
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
#include<string.h>
#include<utility>
#include<set>
#include<cmath>
#include<queue>
#include<deque>
#include<functional>
#include<stack>
#include<limits.h>
#include<iomanip>
#include<unordered_map> 
#include<numeric>
#include<tuple>
#include<bitset>
using namespace std;
 
#define MOD 1000000007
#define int long long
#define ff first
#define ss second
#define endl '\n'
const int mxN=1e5+1;
map<int,int> mp[mxN];
vector<int> v[mxN],d(mxN),w(mxN);
void dfs(int a){
	for(auto node: v[a]){
		dfs(node);
		if(mp[a].size()<mp[node].size()) swap(mp[a],mp[node]);
		for(auto x: mp[node]) mp[a][x.ff]+=x.ss;
	}
	if(d[a]>0){
		mp[a][d[a]]+=w[a];
		while(true){
			auto it=mp[a].upper_bound(d[a]);
			if(it==mp[a].end()) break;
			if(it->ss<w[a]){
				w[a]-=it->ss;
				mp[a].erase(it);
				continue;
			}
			it->ss-=w[a];
			break;
		}
	}
}
void solve(){
	int n,m,k; cin>>n>>m>>k;
	for(int i=2; i<=n; i++){
		int a; cin>>a;
		v[a].push_back(i);
	}
	for(int i=1; i<=m; i++){
		int a; cin>>a;
		cin>>d[a]>>w[a];
	}
	dfs(1);
	int ans=0;
	for(auto x: mp[1]) ans+=x.ss;
	cout<<ans;
}
signed main(){
    // freopen("file.in", "r", stdin);
    // freopen("file.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int t=1;
    // cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
    return 0;
}





















# Verdict Execution time Memory Grader output
1 Correct 2 ms 8884 KB Output is correct
2 Correct 2 ms 9088 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 2 ms 9304 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 2 ms 9052 KB Output is correct
9 Correct 3 ms 9048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 19584 KB Output is correct
2 Correct 41 ms 21584 KB Output is correct
3 Correct 104 ms 38204 KB Output is correct
4 Correct 65 ms 21248 KB Output is correct
5 Correct 79 ms 23376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9052 KB Output is correct
2 Correct 3 ms 9072 KB Output is correct
3 Correct 3 ms 9096 KB Output is correct
4 Correct 40 ms 28196 KB Output is correct
5 Correct 66 ms 32084 KB Output is correct
6 Correct 63 ms 28244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 16720 KB Output is correct
2 Correct 55 ms 15952 KB Output is correct
3 Correct 39 ms 20444 KB Output is correct
4 Correct 30 ms 17104 KB Output is correct
5 Correct 38 ms 28240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8884 KB Output is correct
2 Correct 2 ms 9088 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 2 ms 9304 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 2 ms 9052 KB Output is correct
9 Correct 3 ms 9048 KB Output is correct
10 Correct 50 ms 20052 KB Output is correct
11 Correct 53 ms 18772 KB Output is correct
12 Correct 51 ms 20040 KB Output is correct
13 Correct 30 ms 16580 KB Output is correct
14 Correct 35 ms 27732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9560 KB Output is correct
2 Correct 18 ms 11572 KB Output is correct
3 Correct 19 ms 11592 KB Output is correct
4 Correct 17 ms 11612 KB Output is correct
5 Correct 7 ms 10460 KB Output is correct
6 Correct 29 ms 14332 KB Output is correct
7 Correct 21 ms 17752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8884 KB Output is correct
2 Correct 2 ms 9088 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 2 ms 9304 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 2 ms 9052 KB Output is correct
9 Correct 3 ms 9048 KB Output is correct
10 Correct 3 ms 9052 KB Output is correct
11 Correct 3 ms 9072 KB Output is correct
12 Correct 3 ms 9096 KB Output is correct
13 Correct 40 ms 28196 KB Output is correct
14 Correct 66 ms 32084 KB Output is correct
15 Correct 63 ms 28244 KB Output is correct
16 Correct 50 ms 20052 KB Output is correct
17 Correct 53 ms 18772 KB Output is correct
18 Correct 51 ms 20040 KB Output is correct
19 Correct 30 ms 16580 KB Output is correct
20 Correct 35 ms 27732 KB Output is correct
21 Correct 16 ms 12888 KB Output is correct
22 Correct 56 ms 21392 KB Output is correct
23 Correct 68 ms 25572 KB Output is correct
24 Correct 135 ms 37460 KB Output is correct
25 Correct 50 ms 20408 KB Output is correct
26 Correct 71 ms 23444 KB Output is correct
27 Correct 66 ms 22356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8884 KB Output is correct
2 Correct 2 ms 9088 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 2 ms 9304 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 2 ms 9052 KB Output is correct
9 Correct 3 ms 9048 KB Output is correct
10 Correct 42 ms 19584 KB Output is correct
11 Correct 41 ms 21584 KB Output is correct
12 Correct 104 ms 38204 KB Output is correct
13 Correct 65 ms 21248 KB Output is correct
14 Correct 79 ms 23376 KB Output is correct
15 Correct 3 ms 9052 KB Output is correct
16 Correct 3 ms 9072 KB Output is correct
17 Correct 3 ms 9096 KB Output is correct
18 Correct 40 ms 28196 KB Output is correct
19 Correct 66 ms 32084 KB Output is correct
20 Correct 63 ms 28244 KB Output is correct
21 Correct 45 ms 16720 KB Output is correct
22 Correct 55 ms 15952 KB Output is correct
23 Correct 39 ms 20444 KB Output is correct
24 Correct 30 ms 17104 KB Output is correct
25 Correct 38 ms 28240 KB Output is correct
26 Correct 50 ms 20052 KB Output is correct
27 Correct 53 ms 18772 KB Output is correct
28 Correct 51 ms 20040 KB Output is correct
29 Correct 30 ms 16580 KB Output is correct
30 Correct 35 ms 27732 KB Output is correct
31 Correct 6 ms 9560 KB Output is correct
32 Correct 18 ms 11572 KB Output is correct
33 Correct 19 ms 11592 KB Output is correct
34 Correct 17 ms 11612 KB Output is correct
35 Correct 7 ms 10460 KB Output is correct
36 Correct 29 ms 14332 KB Output is correct
37 Correct 21 ms 17752 KB Output is correct
38 Correct 16 ms 12888 KB Output is correct
39 Correct 56 ms 21392 KB Output is correct
40 Correct 68 ms 25572 KB Output is correct
41 Correct 135 ms 37460 KB Output is correct
42 Correct 50 ms 20408 KB Output is correct
43 Correct 71 ms 23444 KB Output is correct
44 Correct 66 ms 22356 KB Output is correct
45 Correct 15 ms 12636 KB Output is correct
46 Correct 58 ms 20852 KB Output is correct
47 Correct 74 ms 24344 KB Output is correct
48 Correct 99 ms 34388 KB Output is correct
49 Correct 53 ms 21200 KB Output is correct
50 Correct 75 ms 23676 KB Output is correct
51 Correct 81 ms 22484 KB Output is correct