| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1358196 | Aviansh | Magic Tree (CEOI19_magictree) | C++20 | 80 ms | 42156 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxn = 1e5+5;
map<int,int> mps[mxn];
void dfs(int st, vector<int>g[], int d[], int w[]){
for(int i : g[st])
dfs(i,g,d,w);
mps[st].clear();
mps[st][0]=0;
for(int i : g[st]){
if(mps[i].size()>mps[st].size()){
swap(mps[st],mps[i]);
}
for(pair<int,int>p:mps[i]){
mps[st][p.first]+=p.second;
}
}
auto it = mps[st].upper_bound(d[st]);
int sum = 0;
while(it!=mps[st].end()){
sum+=(*it).second;
if(sum>w[st]){
mps[st][(*it).first]=sum-w[st];
break;
}
else{
mps[st].erase(it);
}
it = mps[st].upper_bound(d[st]);
}
mps[st][d[st]]+=w[st];
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m,k;
cin >> n >> m >> k;
vector<int>g[n];
for(int i = 1;i<n;i++){
int p;
cin >> p;
p--;
g[p].push_back(i);
}
int d[n];
int w[n];
fill(d,d+n,0);
fill(w,w+n,0);
for(int i = 0;i<m;i++){
int v,curd,curw;
cin >> v >> curd >> curw;
v--;
d[v]=curd;
w[v]=curw;
}
dfs(0,g,d,w);
int ans = 0;
for(pair<int,int>p:mps[0]){
ans+=p.second;
}
cout << ans;
return 0;
}
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
