Submission #949351

# Submission time Handle Problem Language Result Execution time Memory
949351 2024-03-19T06:46:33 Z Minbaev Magic Tree (CEOI19_magictree) C++17
0 / 100
43 ms 49244 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define f first
#define int long long
#define s second
#define pii pair<int,int>

template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
	tree_order_statistics_node_update> ordered_set;
	
const int N = 1e6 + 5;
const int inf = 1e17 + 7;
const int mod = 1e9 + 7;

int n,m,k;
vector<int>g[N],w(N),type(N),dp(N);

pii dfs(int x, int pr){
	
	pii sum = {0,0};
	
	for(auto to:g[x]){
		if(to == pr)continue;
		
		pii val = dfs(to,x);
		
		if(type[to] == type[x]){
			dp[x] += dp[to] + w[to];
		}
		else if(type[x] == 2){
			dp[x] += max(val.f, dp[to]);
		}
		else{
			dp[x] += dp[to] + w[to];
		}
		
		if(type[to] == 1){
			sum.f += w[to];
		}
		if(type[to] == 2){
			sum.s += w[to];
		}
		sum.f += val.f;
		sum.s += val.s;
	}
	
	if(type[x] == 1)sum.f += w[x];
	else sum.s += w[x];
	
	return sum;
	
}

void solve(){
	
	cin >> n >> m >> k;
	
	for(int i = 2;i<=n;i++){
		int a;
		cin >> a;
		g[a].pb(i);
	}
	
	for(int i = 1;i<=m;i++){
		int a,b,c;
		cin >> a >> b >> c;
		type[a] = c;
		w[a] = b;
	}
	
	dfs(1,-1);
	
	cout << dp[1] <<'\n';
	
}
/*
6 6 2
1
2
3
4
5
1 1 1
2 2 2
3 3 1
4 4 2
5 5 2
6 6 1
// Success consists of going from failure to failure without loss of enthusiasm
// Problems means that you are trying
// Soberis dolboyeb
*/
signed main()
{
	
//	freopen("seq.in", "r", stdin);
//  freopen("seq.out", "w", stdout);
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int tt=1;//cin>>tt;
	while(tt--)solve();

}

# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 47192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 49036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 47452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 49244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 47192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 47704 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 47192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 47192 KB Output isn't correct
2 Halted 0 ms 0 KB -