Submission #775744

#TimeUsernameProblemLanguageResultExecution timeMemory
775744danikoynovMagic Tree (CEOI19_magictree)C++14
34 / 100
2078 ms31092 KiB
/** ____ ____ ____ ____ ____ ____ ||l |||e |||i |||n |||a |||d || ||__|||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\|/__\| **/ #include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int maxn = 1e5 + 10, maxk = 21; int n, m, k, p[maxn], w[maxn], d[maxn]; ll dp[maxn][maxk], diff[maxn][maxk]; vector < int > adj[maxn]; void dfs(int v) { for (int u : adj[v]) { dfs(u); for (int j = 0; j <= k; j ++) diff[v][j] += diff[u][j]; } if (d[v] != 0) { diff[v][d[v] - 1] += w[v]; diff[v][d[v]] -= w[v]; int pt = d[v]; while(pt < k) { if (diff[v][pt] < 0) { diff[v][pt + 1] += diff[v][pt]; diff[v][pt] = 0; pt ++; } else { break; } } } /**for (int j = 0; j < k; j ++) { if (diff[v][j] < 0) { diff[v][j + 1] += diff[v][j]; diff[v][j] = 0; } }*/ } void solve() { cin >> n >> m >> k; for (int i = 2; i <= n; i ++) { cin >> p[i]; adj[p[i]].push_back(i); } for (int i = 1; i <= m; i ++) { int v; cin >> v >> d[v] >> w[v]; } dfs(1); ll ans = 0; for (int j = 0; j < k; j ++) ans = ans + diff[1][j]; cout << ans << endl; } int main() { solve(); return 0; } /** 6 4 10 1 2 1 4 4 3 3 4 4 2 5 5 5 1 6 3 9 */
#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...