#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#define int long long
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const ll inf = 0x3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 2e5 + 11;
const int INF = 2e9;
const ll INF64 = 3e18 + 1;
const double lil = 0.0000000000001;
//ifstream cin ("test.in");
//ofstream cout ("test.out");
int n, m, day[N], dp[N], val[N], k;
vector<int>v[N];
void dfs(int nod){
if(sz(v[nod]) == 0){
dp[nod] = val[nod];
return;
}
for(auto it : v[nod]){
dfs(it);
}
int small = 0, big = 0, mxbig = 0, mxsmall = 0;
for(auto it : v[nod]){
if(day[it] > day[nod]){
big += dp[it];
mxbig = max(mxbig, day[it]);
}else{
small += dp[it];
mxsmall = max(mxsmall, day[it]);
}
}
if(val[nod] == big){
day[nod] = max(mxsmall, min(day[nod], mxbig));
dp[nod] = big + small;
}else
if(val[nod] < big){
day[nod] = max(mxsmall, mxbig);
dp[nod] = big + small;
}else{
day[nod] = max(mxsmall, day[nod]);
dp[nod] = val[nod] + small;
}
}
int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
cin >> n >> m >> k;
for(int i = 2, x; i <= n; i++){
cin >> x;
v[x].pb(i);
}
for(int i = 1, p, d, x; i <= m; i++){
cin >> p >> d >> x;
val[p] = x;
day[p] = d;
}
dfs(1);
rc(dp[1]);
//for(int i = 1; i <= n; i++)cout << dp[i] << ' '; cout << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4992 KB |
Output is correct |
2 |
Correct |
9 ms |
4992 KB |
Output is correct |
3 |
Correct |
7 ms |
4992 KB |
Output is correct |
4 |
Correct |
9 ms |
4992 KB |
Output is correct |
5 |
Correct |
8 ms |
4992 KB |
Output is correct |
6 |
Incorrect |
7 ms |
4992 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
10232 KB |
Output is correct |
2 |
Correct |
46 ms |
13432 KB |
Output is correct |
3 |
Correct |
63 ms |
11128 KB |
Output is correct |
4 |
Correct |
58 ms |
10352 KB |
Output is correct |
5 |
Correct |
59 ms |
11896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5248 KB |
Output is correct |
2 |
Incorrect |
9 ms |
5248 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
73 ms |
11384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4992 KB |
Output is correct |
2 |
Correct |
9 ms |
4992 KB |
Output is correct |
3 |
Correct |
7 ms |
4992 KB |
Output is correct |
4 |
Correct |
9 ms |
4992 KB |
Output is correct |
5 |
Correct |
8 ms |
4992 KB |
Output is correct |
6 |
Incorrect |
7 ms |
4992 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
6016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4992 KB |
Output is correct |
2 |
Correct |
9 ms |
4992 KB |
Output is correct |
3 |
Correct |
7 ms |
4992 KB |
Output is correct |
4 |
Correct |
9 ms |
4992 KB |
Output is correct |
5 |
Correct |
8 ms |
4992 KB |
Output is correct |
6 |
Incorrect |
7 ms |
4992 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4992 KB |
Output is correct |
2 |
Correct |
9 ms |
4992 KB |
Output is correct |
3 |
Correct |
7 ms |
4992 KB |
Output is correct |
4 |
Correct |
9 ms |
4992 KB |
Output is correct |
5 |
Correct |
8 ms |
4992 KB |
Output is correct |
6 |
Incorrect |
7 ms |
4992 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |