This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Parsa Jokar 2023 https://github.com/phictus/ioi
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <cstdint>
using namespace std;
constexpr int64_t maxn = 100000;
int64_t n, m, k, fruitType[maxn + 1], fruitCount[maxn + 1], sum[maxn + 1][3], dp[maxn + 1];
vector<int64_t> adj[maxn + 1];
void Init(int64_t v = 1)
{
sum[v][fruitType[v]] += fruitCount[v];
for (int64_t u : adj[v])
{
Init(u);
sum[v][1] += sum[u][1];
sum[v][2] += sum[u][2];
dp[v] += max(sum[u][1] - sum[u][2], dp[u]);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin >> n >> m >> k;
for (int64_t i = 2; i <= n; i++)
{
int64_t p;
cin >> p;
adj[p].push_back(i);
}
int64_t poop = 0;
for (int64_t i = 1; i <= m; i++)
{
int64_t v;
cin >> v;
cin >> fruitType[v] >> fruitCount[v];
poop += fruitCount[v];
}
if (k > 2)
cout << poop << '\n';
else
{
Init();
cout << sum[1][2] + dp[1] << '\n';
}
return (0 ^ 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... |