#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] == 1){
dp[x] += max(val.f, dp[to]);
}
else{
dp[x] += dp[to] + 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);
for(int i = 1;i<=n;i++){
cout << dp[i] << " ";
break;
}
}
/*
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 |
17 ms |
47196 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
48984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
47452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
49244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
47196 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
47704 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
47196 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
47196 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |