Submission #723537

#TimeUsernameProblemLanguageResultExecution timeMemory
723537dxz05Magic Tree (CEOI19_magictree)C++17
0 / 100
2058 ms8624 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(), (x).end() #define MP make_pair const int N = 100500; vector<int> g[N]; int tin[N], tout[N], timer = 0; void dfs(int v){ tin[v] = tout[v] = ++timer; for (int u : g[v]){ dfs(u); tout[v] = tout[u]; } } bool is_ancestor(int p, int v){ return tin[p] <= tin[v] && tout[v] <= tout[p]; } void solve(){ int n, m, k; cin >> n >> m >> k; for (int i = 2; i <= n; i++){ int p; cin >> p; g[p].push_back(i); } dfs(1); vector<tuple<int, int, int>> fruits; for (int i = 0; i < m; i++){ int v, d, w; cin >> v >> d >> w; fruits.emplace_back(v, d, w); } ll ans = 0; for (int i = 0; i < m; i++){ ll sum = 0; int v = get<0>(fruits[i]); for (int j = 0; j < m; j++){ if (i == j) continue; auto [u, d, w] = fruits[j]; if (is_ancestor(v, u) && d > get<1>(fruits[i])) sum += w; } if (sum <= get<2>(fruits[i])){ ans += get<2>(fruits[i]); } } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif solve(); 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...