# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
673551 | Cutebol | Biochips (IZhO12_biochips) | C++17 | 280 ms | 401664 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;
void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define Scaramouche ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);
//#define int long long
#define itn int
#define endl "\n"
#define ff first
#define ss second
const int N = 2e5 + 5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e9 ;
int n , m , s , timer = 1 ;
int a[N] , p , b[N] , tin[N] ;
int dp[N][505] ;
vector <int> g[N] ;
void dfs( int v ){
int tt = timer ;
for ( auto to : g[v] ) dfs(to) ;
tin[timer] = tt ;
b[timer] = a[v] ;
timer ++ ;
}
void solve(){
cin >> n >> m ;
for ( int i = 1 ; i <= n ; i ++ ){
cin >> p >> a[i] ;
if (!p) s = i ;
else g[p].push_back(i) ;
}
dfs(s) ;
for ( int i = 0 ; i <= n ; i ++ ) {
for ( int j = 1 ; j <= m ; j ++ ) {
dp[i][j] = -inf ;
}
}
for ( int i = 1 ; i <= n ; i ++ ){
for ( int 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(){
// fopn("blocks") ;
Scaramouche ;
int t = 1 ;
// cin >> t ;
while ( t -- ) solve() ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |