# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1115888 | guagua0407 | Magic Tree (CEOI19_magictree) | C++17 | 147 ms | 34120 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.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const int mxn=1e5+5;
vector<int> adj[mxn];
multiset<pair<int,int>> S[mxn];
int d[mxn];
int w[mxn];
void dfs(int v,int p=0){
for(auto u:adj[v]){
dfs(u,v);
if(S[v].size()<S[u].size()){
swap(S[v],S[u]);
}
for(auto x:S[u]){
S[v].insert(x);
}
}
auto it=S[v].lower_bound({d[v]+1,0});
int sum=0;
while(it!=S[v].end() and sum+(*it).s<=w[v]){
sum+=(*it).s;
it=S[v].erase(it);
}
if(it!=S[v].end()){
auto p=(*it);
S[v].erase(it);
p.s=sum+p.s-w[v];
S[v].insert(p);
}
S[v].insert({d[v],w[v]});
}
signed main() {_
int n,m,k;
cin>>n>>m>>k;
for(int i=2;i<=n;i++){
int p;
cin>>p;
adj[p].push_back(i);
}
for(int i=0;i<m;i++){
int v;
cin>>v;
cin>>d[v]>>w[v];
}
dfs(1);
ll ans=0;
for(auto v:S[1]){
ans+=v.s;
}
cout<<ans<<'\n';
return 0;
}
//maybe its multiset not set
//yeeorz
//diaoborz
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... |