#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define u_map unordered_map
const int maxn = 1e3 + 5, mod = 1e9 + 7;
vector<int> adj[maxn];
int d[maxn], w[maxn], dp[maxn][maxn], sum;
int n, m, k;
void sfd(int v, int x) {
if (d[v] == x)
sum += w[v];
for (int u: adj[v]) {
sfd(u, x);
}
}
void dfs(int v) {
for (int u: adj[v]) {
dfs(u);
}
for (int i = k; i >= 1; i--) {
sum = 0;
sfd(v, i);
int mus = 0;
for (int u: adj[v]) {
mus += dp[u][i];
}
dp[v][i] = max({sum, mus, dp[v][i + 1]});
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> m >> k;
for (int i = 2; i <= n; i++) {
int p;
cin >> p;
adj[p].pb(i);
}
for (int i = 1; i <= m; i++) {
int _v, _d, _w;
cin >> _v >> _d >> _w;
d[_v] = _d;
w[_v] = _w;
}
dfs(1);
cout << dp[1][1];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2056 ms |
4088 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
4696 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |