이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define N 7<<14
#define int long long
vector<int>adj[N];
map<int,int> dp[N];
int d[N],w[N];
void dfs(int n){
map<int,int> add;
dp[n][0];
for(auto i:adj[n]){
dfs(i);
if(size(dp[n])+size(add)<size(dp[i])) {
add[0];
auto it=++add.begin();
while(it!=add.end()){
it->second+=prev(it)->second;
it++;
}
for(auto[i,j]:add)
dp[n][i]=(--(dp[n].upper_bound(i)))->second;
for(auto&[i,j]:dp[n])
j+=(--(add.upper_bound(i)))->second;
add.clear();
swap(dp[n],dp[i]);
}
auto it=++dp[i].begin();
while(it!=dp[i].end())
add[it->first]+=it->second-prev(it)->second,it++;
dp[i].clear();
}
add[0];
auto it=++add.begin();
while(it!=add.end()){
it->second+=prev(it)->second;
it++;
}
for(auto[i,j]:add)
dp[n][i]=(--(dp[n].upper_bound(i)))->second;
for(auto&[i,j]:dp[n])
j+=(--(add.upper_bound(i)))->second;
it=--(dp[n].upper_bound(d[n]));
int val=it->second+w[n];
dp[n][d[n]]=val;
it=dp[n].find(d[n]);
while(it!=dp[n].end()){
it->second=max(it->second,val);
it++;
}
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n,m,k,Q;
cin>>n>>m>>k;
for(int i=2;i<=n;i++)
cin>>Q,adj[Q].push_back(i);
while(m--){
int a,b,c;
cin>>a>>b>>c;
d[a]=b,w[a]=c;
}
dfs(1);
cout<<(--dp[1].end())->second;
}
# | 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... |