#include "bits/stdc++.h"
using namespace std;
#define ar array
typedef int64_t ll;
#define int ll
const int N = 1e5 + 5;
vector<int> edges[N];
int is[N], d[N], w[N], mx[N];
map<int, int> sub[N];
void dfs(int u){
mx[u] = u;
for(auto x : edges[u]){
dfs(x);
if(sub[x].size() > sub[mx[u]].size()) mx[u] = x;
}
swap(sub[u], sub[mx[u]]);
for(auto x : edges[u]){
if(x == mx[u]) continue;
for(auto v : sub[x]){
sub[u][v.first] += v.second;
}
sub[x].clear();
}
if(is[u]){
sub[u][d[u]] += w[u];
auto it = sub[u].upper_bound(d[u]);
vector<int> er;
while(it != sub[u].end()){
w[u] -= (*it).second;
if(w[u] <= 0){
if(w[u]) sub[u][(*it).first] = -w[u];
break;
}
er.push_back((*it).first);
}
for(auto x : er){
sub[u].erase(x);
}
}
}
signed 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 x; cin>>x;
edges[x].push_back(i);
}
for(int i=0;i<m;i++){
int v; cin>>v;
cin>>d[v]>>w[v];
is[v] = 1;
}
dfs(1);
int sum = 0;
for(auto x : sub[1]) sum += x.second;
cout<<sum<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
14976 KB |
Output is correct |
2 |
Correct |
44 ms |
19936 KB |
Output is correct |
3 |
Correct |
119 ms |
18428 KB |
Output is correct |
4 |
Correct |
77 ms |
17684 KB |
Output is correct |
5 |
Correct |
93 ms |
17612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
7636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
12404 KB |
Output is correct |
2 |
Correct |
76 ms |
12280 KB |
Output is correct |
3 |
Correct |
54 ms |
19244 KB |
Output is correct |
4 |
Correct |
57 ms |
16904 KB |
Output is correct |
5 |
Correct |
63 ms |
29180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
10 ms |
8332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |