This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("avx2")
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define all(m) (m).begin(), (m).end()
#define rall(m) (m).rbegin(), (m).rend()
#define vec vector
#define sz(a) (int) (a).size()
#define mpp make_pair
#define mtt make_tuple
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tui;
template <typename T>
using prq = priority_queue <T>;
template <typename T>
using pgq = priority_queue <T, vec <T>, greater <T>>;
template <typename T> bool umin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> bool umax(T &a, T b) { return a < b ? a = b, 1 : 0; }
inline int solve(){
int n, m, k;
cin >> n >> m >> k;
vec <vec <int>> g(n);
for (int i = 1; i < n; ++i){
int p; cin >> p, --p;
g[p].push_back(i);
}
vec <int> d(n), w(n);
for (int i = 0; i < m; ++i){
int u, x, y;
cin >> u >> x >> y, --u;
d[u] = x, w[u] = y;
}
vec <vec <ll>> dp(n, vec <ll> (k + 1));
auto dfs = [&](auto &&dfs, int u) -> void{
for (auto &v: g[u]){
dfs(dfs, v);
for (int i = 1; i <= k; ++i){
dp[u][i] += dp[v][i];
}
}
if (d[u] != 0){
ll nw = dp[u][d[u]] + w[u];
for (int i = d[u]; i <= k; ++i){
umax(dp[u][i], nw);
}
}
};
dfs(dfs, 0);
cout << *max_element(all(dp[0]));
return 0;
}
inline void precalc(){}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int tst = 1; //cin >> tst;
precalc();
while(tst--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |