# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
532148 | Yazan_Alattar | Magic Tree (CEOI19_magictree) | C++14 | 133 ms | 37272 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>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 100007;
const ll inf = 1e18;
const ll mod = 998244353;
const double pi = acos(-1);
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;
vector <int> adj[M];
map <ll,ll> dp[M];
int n, m, k, ripe[M], w[M];
void dfs(int node){
for(auto i : adj[node]){
dfs(i);
if(dp[i].size() > dp[node].size()) swap(dp[i], dp[node]);
for(auto j : dp[i]) dp[node][j.F] += j.S;
}
dp[node][ripe[node]] += w[node];
ll rem = w[node];
while(1){
auto i = dp[node].lower_bound(ripe[node] + 1);
if(i == dp[node].end()) break;
if(i->S > rem){
i->S -= rem;
break;
}
else{
rem -= i->S;
dp[node].erase(i);
}
}
return;
}
int main(){
scanf("%d%d%d", &n, &m, &k);
for(int i = 2; i <= n; ++i){
int p; scanf("%d", &p);
adj[p].pb(i);
}
for(int i = 1; i <= m; ++i){
int x;
scanf("%d", &x);
scanf("%d%d", &ripe[x], &w[x]);
}
dfs(1);
ll ans = 0;
for(auto i : dp[1]) ans += i.S;
printf("%lld\n", ans);
return 0;
}
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... |