#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], w[i]}).fi;
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
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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
16812 KB |
Output is correct |
2 |
Correct |
23 ms |
9808 KB |
Output is correct |
3 |
Correct |
111 ms |
39860 KB |
Output is correct |
4 |
Correct |
74 ms |
17748 KB |
Output is correct |
5 |
Correct |
71 ms |
22864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
12112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5724 KB |
Output is correct |
2 |
Correct |
9 ms |
7088 KB |
Output is correct |
3 |
Correct |
8 ms |
7000 KB |
Output is correct |
4 |
Correct |
9 ms |
7108 KB |
Output is correct |
5 |
Correct |
6 ms |
6488 KB |
Output is correct |
6 |
Correct |
9 ms |
7004 KB |
Output is correct |
7 |
Correct |
10 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |