Submission #896400

#TimeUsernameProblemLanguageResultExecution timeMemory
896400math_rabbit_1028Magic Tree (CEOI19_magictree)C++14
3 / 100
47 ms5444 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; int n, m, k, par[101010]; pii arr[101010]; int cnt[101010]; priority_queue<pii> pq; ll ans = 0; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k; for (int i = 2; i <= n; i++) cin >> par[i]; for (int i = 1; i <= m; i++) { int v, d, w; cin >> v >> d >> w; arr[v] = {d, w}; } for (int i = 2; i <= n; i++) cnt[par[i]]++; for (int i = 1; i <= n; i++) { if (cnt[i] == 0) pq.push({-arr[i].first, i}); } int now = 1; while (!pq.empty()) { while (!pq.empty() && now >= -pq.top().first) { int v = pq.top().second; if (now == -pq.top().first) ans += arr[v].second; pq.pop(); cnt[par[v]]--; if (par[v] > 1 && cnt[par[v]] == 0) pq.push({arr[par[v]].first, par[v]}); } now++; } cout << ans << "\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...