# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
909256 | lighton | Magic Tree (CEOI19_magictree) | C++17 | 2097 ms | 860964 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 forf(i,a,b) for(int i = a; i<=b; i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
int N,M,K;
int inf = 1e9;
struct ST{
int t; ll v; int id;
bool operator<(const ST &r) const{
if(t==r.t) return id<r.id;
return t<r.t;
}
};
set<ST> s[200001];
vector<int> adj[200001];
ST upd[200001];
set<ST> merg (set<ST> a, set<ST> b){
set<ST> ret;
for(ST i : a) ret.insert(i);
for(ST i : b) ret.insert(i);
return ret;
}
void add (set<ST> &now, ST a){
ST tmp = a; tmp.id = inf;
now.insert(a);
auto it = now.upper_bound(tmp);
ll sum = 0; int flag = 0;
ST nxt;
while(it != now.end() && sum <= a.v){
sum += it->v;
if(sum > a.v){
nxt = *it;
flag = 1;
}
it = now.erase(it);
}
if(flag){
nxt.v = sum-a.v;
now.insert(nxt);
}
}
void dfs(int now ,int p = -1){
for(int &i : adj[now]){
if(i==p) continue;
dfs(i,now);
s[now] = merg(s[now],s[i]);
}
if(upd[now].id) add(s[now],upd[now]);
}
int main(){
scanf("%d %d %d" , &N,&M,&K);
forf(i,2,N){
int t; scanf("%d" , &t);
adj[i].push_back(t);
adj[t].push_back(i);
}
forf(i,1,M){
int u,t; ll v; scanf("%d %d %lld" , &u,&t, &v);
upd[u] = {t,v,i};
}
dfs(1);
ll ans = 0;
for(ST i : s[1]) ans += i.v;
printf("%lld" , ans);
}
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... |