#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("HCN.INP");
ofstream fout("HCN.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
//using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 9;
const int mxn = 1e5 + 5, mxq = 2e5 + 5, sq = 200, mxv = 2e6 + 5;
const ll inf = 1e17 + 5;
//const int base= (1 << 18);
int n, m, k;
vt<int>adj[mxn + 1];
int day[mxn + 1];
ll cost[mxn + 1], dp[23][mxn + 1], sub[mxn + 1];
void ckmax(ll &a, ll b){
a = max(a, b);
}
void dfs(int tme, int s){
dp[tme][s] = dp[tme + 1][s];
ll tot = 0;
if(day[s] == tme){
sub[s] = cost[s];
}
for(auto i: adj[s]){
dfs(tme, i);
tot += dp[tme][i];
sub[s] += sub[i];
}
ckmax(dp[tme][s], tot);
ckmax(dp[tme][s], sub[s]);
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m >> k;
for(int i = 2; i <= n; i++){
int p; cin >> p;
adj[p].pb(i);
}
for(int i = 0; i < m; i++){
int v; cin >> v;
cin >> day[v] >> cost[v];
}
ll ans = 0;
for(int i = k; i >= 1; i--){
dfs(i, 1);
for(int j = 1; j <= n; j++){
ckmax(ans, dp[i][j]);
sub[j] = 0;
}
}
cout << ans;
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
12124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
19 ms |
10840 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
5 ms |
8028 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
37 ms |
8804 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
12124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
8536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
12124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
12124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |