제출 #1128250

#제출 시각아이디문제언어결과실행 시간메모리
1128250VMaksimoski008Magic Tree (CEOI19_magictree)C++20
34 / 100
125 ms30940 KiB
#include <bits/stdc++.h> #define ar array //#define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; vector<int> G[maxn]; int d[maxn], w[maxn], n, m, k; ll dp[maxn][21]; void dfs(int u) { dp[u][d[u]] = w[u]; for(int v : G[u]) { dfs(v); for(int i=0; i<=20; i++) { ll mx = 0; for(int j=0; j<=i; j++) mx = max(mx, dp[v][j]); dp[u][i] += mx; } } } signed main() { cin >> n >> m >> k; for(int i=2; i<=n; i++) { int p; cin >> p; G[p].push_back(i); } for(int i=1; i<=m; i++) { int a, b, c; cin >> a >> b >> c; d[a] = b; w[a] = c; } dfs(1); cout << dp[1][20] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...