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>
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 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... |