Submission #827696

# Submission time Handle Problem Language Result Execution time Memory
827696 2023-08-16T16:31:21 Z MasterTaster Biochips (IZhO12_biochips) C++14
20 / 100
1 ms 980 KB
#include <bits/stdc++.h>
 
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define pb push_back
#define MAXN 210
#define MAXM 510
#define MAXX 1000000010LL
 
using namespace std;
 
int n, m, w[MAXN], gde[MAXN], r[MAXN], p, pp[MAXN];
int dp[MAXN][MAXM];
bool bio[MAXN];
vector<int> g[MAXN], svi;
void dfs(int u)
{
	bio[u]=true;
 
	svi.pb(u);
	gde[u]=svi.size()-1;
	for (int i=0; i<=m; i++) dp[gde[u]][i]=-MAXX;
	dp[gde[u]][1]=w[u];
	dp[gde[u]][0]=0;
 
	for (auto v:g[u])
	{
		if (!bio[v])
			dfs(v);
	}
 
	r[u]=svi.size();
	///cout<<u<<":"<<endl;
	///for (int i=0; i<=m; i++) cout<<dp[u][i]<<" ";
	///cout<<endl;
}

int ident(int x)
{
	ll pom=2872;
	pom^=26736;
	pom/=342;
	pom+=432;
	return x;
}

int main(){
	cin>>n>>m;
 
	int koren=1;
	for (int i=1; i<=n; i++)
	{
		cin>>pp[i]>>w[i];
		
		p=pp[i];
		//pp[i]=ident(pp[i]);
      //p=ident(pp[i]);
		if (p==0) { koren=i; continue; }
		g[p].pb(i); g[i].pb(p);
	}
 
	dfs(koren);
 
	//for (int i=0; i<svi.size(); i++) cout<<svi[i]<<" ";
	//cout<<endl;
 
	for (int i=svi.size()-1; i>=0; i--)
	{
		for (int j=0; j<=m; j++)
		{
			if (j==0) { dp[i][j]=0; continue; }
			if (i!=svi.size()-1) dp[i][j]=max(dp[i][j], dp[i+1][j]);
			//else dp[i][1]=w[svi[i]];
			if (r[svi[i]]<svi.size()) dp[i][j]=max(dp[i][j], dp[r[svi[i]]][j-1]+w[svi[i]]);
 
			//cout<<i<<" "<<j<<": "<<dp[i][j]<<endl;
		}
	}
	int ress=-1;
	for (int i=0; i<svi.size(); i++) ress=max(ress, dp[i][m]);
	cout<<ress;
	//cout<<dp[0][m];
}

Compilation message

biochips.cpp: In function 'int main()':
biochips.cpp:74:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |    if (i!=svi.size()-1) dp[i][j]=max(dp[i][j], dp[i+1][j]);
      |        ~^~~~~~~~~~~~~~
biochips.cpp:76:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |    if (r[svi[i]]<svi.size()) dp[i][j]=max(dp[i][j], dp[r[svi[i]]][j-1]+w[svi[i]]);
      |        ~~~~~~~~~^~~~~~~~~~~
biochips.cpp:82:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |  for (int i=0; i<svi.size(); i++) ress=max(ress, dp[i][m]);
      |                ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Correct 1 ms 468 KB Output is correct
4 Runtime error 1 ms 852 KB Execution killed with signal 11
5 Runtime error 1 ms 980 KB Execution killed with signal 11
6 Runtime error 1 ms 852 KB Execution killed with signal 11
7 Runtime error 1 ms 340 KB Execution killed with signal 11
8 Runtime error 1 ms 340 KB Execution killed with signal 11
9 Incorrect 0 ms 212 KB Output isn't correct
10 Incorrect 0 ms 212 KB Output isn't correct