# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199821 | quocnguyen1012 | Magic Tree (CEOI19_magictree) | C++14 | 195 ms | 37112 KiB |
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>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
vector<int> adj[maxn];
map<int, ll> f[maxn];
int N, W[maxn], D[maxn], M, K;
void dfs(int u)
{
for (int v : adj[u]){
dfs(v);
if (f[v].size() > f[u].size()) swap(f[u], f[v]);
for (auto & all : f[v])
f[u][all.fi] += all.se;
}
if (D[u]){
vector<int> vi;
ll sum = 0;
auto it = f[u].upper_bound(D[u]);
for (; it != f[u].end(); ++it){
sum += it->se;
if (W[u] < sum) break;
vi.pb(it->fi);
}
if (it != f[u].end()) it->se = sum - W[u];
for (auto & i : vi) f[u].erase(i);
f[u][D[u]] += W[u];
}
}
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen("A.INP", "r")){
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
}
cin >> N >> M >> K;
for (int i = 2; i <= N; ++i){
int p; cin >> p;
adj[p].pb(i);
}
for (int i = 1; i <= M; ++i){
int u; cin >> u;
cin >> D[u] >> W[u];
}
dfs(1);
ll ret = 0;
for (auto it : f[1]) ret += it.se;
cout << ret;
}
Compilation message (stderr)
# | 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... |