Submission #922685

# Submission time Handle Problem Language Result Execution time Memory
922685 2024-02-06T01:56:01 Z thunopro Biochips (IZhO12_biochips) C++14
20 / 100
2000 ms 227748 KB
#include<bits/stdc++.h>
using namespace std ; 
#define maxn 200009 
#define ll long long 
#define fi first 
#define se second 
#define pb push_back 
#define left id<<1
#define right id<<1|1 
#define re exit(0); 

const int mod = 1e9+7; 
const int INF = 1e9; 

typedef vector<int> vi; 
typedef pair<int,int> pii;
typedef vector<pii> vii;  
typedef vector<ll> vl;

void add ( int &a , int b ) 
{
	a += b ; 
	if ( a > mod ) a -= mod ; 
	if ( a < 0 ) a += mod ; 
}

template <typename T> void chkmin ( T &a , T b ) { if ( a > b ) a = b ; }
template <typename T> void chkmax ( T &a , T b ) { if ( a < b ) a = b ; }

int _pow ( int a , int n ) 
{
	if ( n == 0 ) return 1 ;
	int res = _pow (a,n/2) ; 
	if ( n % 2 ) return 1ll*res*res%mod*a%mod ; 
	else return 1ll*res*res%mod ; 
}

void rf () 
{
	freopen ("bai1.inp","r",stdin) ;
}

int n , m ; 
vi adjList [maxn] ; 
int w [maxn] ; 

int dp [maxn][509] ; 
int f [maxn] ; 
int sz [maxn] , root ; 

void dfs ( int u ) 
{
	for ( auto v : adjList [u] ) 
	{
		dfs (v) ; 
		for ( int i = sz [u] ; i >= 0 ; i -- ) 
		{
			for ( int j = sz [v] ; j >= 0 ; j -- ) 
			{
				chkmax (f[i+j],dp[u][i]+dp[v][j]) ; 
			}
		}
		sz [u] += sz [v] ; 
		for ( int i = 0 ; i <= sz [u] ; i ++ ) dp [u][i] = f [i] , f [i] = 0 ; 
	}
	dp [u][1] = w [u] ; 
	sz [u] ++ ; 
}
int main () 
{
	ios_base::sync_with_stdio(0); 
	cin.tie(0);cout.tie(0); 
//	rf () ; 
	cin >> n >> m ; 
	for ( int i = 1 ; i <= n ; i ++ ) 
	{
		int p ; cin >> p >> w [i] ; 
		adjList [p] . pb (i) ; 
		if ( p == 0 ) root = i ; 
	}
	
	dfs (root) ; 
	
	cout << dp [root][m] ; 
	
}

Compilation message

biochips.cpp: In function 'void rf()':
biochips.cpp:40:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 5468 KB Output isn't correct
2 Correct 2 ms 5468 KB Output is correct
3 Correct 2 ms 5212 KB Output is correct
4 Incorrect 39 ms 23120 KB Output isn't correct
5 Incorrect 47 ms 25172 KB Output isn't correct
6 Incorrect 47 ms 25164 KB Output isn't correct
7 Execution timed out 2064 ms 227544 KB Time limit exceeded
8 Execution timed out 2062 ms 227748 KB Time limit exceeded
9 Execution timed out 2062 ms 99100 KB Time limit exceeded
10 Execution timed out 2045 ms 99520 KB Time limit exceeded