# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
680536 | ReLice | Biochips (IZhO12_biochips) | C++14 | 301 ms | 401712 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;
#define endl "\n"
#define ll int
#define pb push_back
#define sz size()
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll N=2e5+5;
const ll mod=1e9+7;
const ll inf=1e9;
ll n,m;
ll a[N],b[N],tin[N],p;
ll dp[N][505];
ll timer=1;
vector <ll> g[N];
void dfs(ll v){
ll tt=timer;
for(auto to : g[v]) dfs(to);
tin[timer]=tt;
b[timer]=a[v];
timer++;
}
void solve(){
ll i,j,c=0;
cin>>n>>m;
for(i=1;i<=n;i++){
cin>>p>>a[i];
if(!p) {
c=i;
continue;
}
g[p].pb(i);
}
dfs(c);
for(i=0;i<=n;i++){
for(j=1;j<=m;j++){
dp[i][j]=-inf;
}
}
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
dp[i][j]=max(dp[i-1][j],dp[tin[i]-1][j-1]+b[i]);
}
}
cout<<dp[n][m];
}
signed main(){
//fre("");
start();
ll t=1;
//cin>>t;
while(t--)solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |