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;
#define NAME ""
#define ll long long
#define pii pair < int , int >
#define fi first
#define se second
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i ++)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; i --)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i ++)
#define bit(x, i) (((x) >> (i)) & 1ll)
#define mask(x) (1ll << (x))
#define mem(f, x) memset(f, x, sizeof(f))
#define sz(x) (int32_t) (x.size())
const int nmax = 1e5;
int p[nmax + 5], t[nmax + 5], w[nmax + 5];
map < int, ll > s[nmax + 5];
signed main() {
if (fopen(NAME".inp", "r")) {
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
int n, m, k;
cin >> n >> m >> k;
FOR(i, 2, n) {
cin >> p[i];
}
for (; m --;) {
int v;
cin >> v;
cin >> t[v] >> w[v];
}
FORD(i, n, 2) {
if (w[i]) {
map < int, ll > :: iterator it = s[i].insert({t[i], 0}).fi;
(*it).se += w[i];
it = next(it);
int remain = w[i];
while (remain && it != s[i].end()) {
if ((*it).se >= remain) {
(*it).se -= remain;
break;
}
remain -= (*it).se;
s[i].erase(it ++);
}
}
if (sz(s[i]) > sz(s[p[i]])) {
swap(s[i], s[p[i]]);
}
for (auto x: s[i]) {
s[p[i]][x.fi] += x.se;
}
}
ll ans = 0;
for (auto x: s[1]) {
ans += x.se;
}
cout << ans;
return 0;
}
Compilation message (stderr)
magictree.cpp: In function 'int main()':
magictree.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen(NAME".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | freopen(NAME".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |