#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
#include <complex>
using u32 = unsigned;
using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
#define int long long
using namespace std;
using pt = complex<f80>;
#define ALL(x) begin(x), end(x)
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
#define N 100005
set<pair<int, i64>> s[N];
int n, m, k;
i64 dp[N];
basic_string<int> g[N];
void dfs(int u)
{
i64 nocur = 0, cur = 0, fruit = s[u].size(), d;
if (fruit) tie(d, cur) = *s[u].begin();
for (auto v : g[u])
{
dfs(v);
nocur += dp[v];
if (s[v].size() > s[u].size()) s[v].swap(s[u]);
i64 curthis = 0;
for (auto &[x, x2] : s[v])
{
if (x <= d) curthis += x2;
auto it = s[u].lower_bound(make_pair(x, 0));
if (it != s[u].end() and it->first == x)
{
int nw = it->second + x2;
s[u].erase(it);
s[u].emplace(x, nw);
}
else s[u].emplace(x, x2);
}
cur += curthis;
set<pair<int, i64>>().swap(s[v]);
}
if (!fruit) return void(dp[u] = nocur);
dp[u] = max(cur, nocur);
}
signed main()
{
ShinLena;
cin >> n >> m >> k;
for (int i = 2, p; i <= n; ++i) cin >> p, g[p].push_back(i);
for (int v, d, w, i = 0; i < m; ++i)
{
cin >> v >> d >> w;
s[v].emplace(d, w);
}
dfs(1);
cout << dp[1];
return 0;
}
Compilation message
magictree.cpp: In function 'void dfs(long long int)':
magictree.cpp:49:13: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
49 | if (x <= d) curthis += x2;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9052 KB |
Output is correct |
2 |
Correct |
2 ms |
9052 KB |
Output is correct |
3 |
Incorrect |
2 ms |
9052 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
12980 KB |
Output is correct |
2 |
Correct |
31 ms |
21596 KB |
Output is correct |
3 |
Correct |
116 ms |
18460 KB |
Output is correct |
4 |
Correct |
64 ms |
17360 KB |
Output is correct |
5 |
Correct |
83 ms |
20556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
9304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
58 ms |
15700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9052 KB |
Output is correct |
2 |
Correct |
2 ms |
9052 KB |
Output is correct |
3 |
Incorrect |
2 ms |
9052 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9052 KB |
Output is correct |
2 |
Correct |
2 ms |
9052 KB |
Output is correct |
3 |
Incorrect |
2 ms |
9052 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9052 KB |
Output is correct |
2 |
Correct |
2 ms |
9052 KB |
Output is correct |
3 |
Incorrect |
2 ms |
9052 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |