Submission #107877

# Submission time Handle Problem Language Result Execution time Memory
107877 2019-04-26T05:43:44 Z SamAnd Biochips (IZhO12_biochips) C++17
0 / 100
2000 ms 29944 KB
#pragma comment(linker,"/STACK:200000000")
#define _CRT_SECURE_NO_WARNINGS
#define mp make_pair
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <cstring>
void fp();
void sp();
using namespace std;
const int N=200003;

int n,m,pp;
vector<int> a[N];
int b[N];
int v[N];
map<int,int> ans[N];
void dfs(int x,int p)
{
	if(x==2)
		cout<<"";
	for(int i=0;i<a[x].size();++i)
	{
		int h=a[x][i];
		if(h==p)
			continue;
		dfs(h,x);
	}
	if(!a[x].empty())
		v[x]=v[a[x][0]];
	else
	{
		v[x]=x;
		ans[x][0]=0;
	}
	for(int i=1;i<a[x].size();++i)
	{
		ans[0].clear();
		int h=a[x][i];
		for(map<int,int>::iterator it1=ans[v[h]].begin();it1!=ans[v[h]].end();++it1)
		{
			for(map<int,int>::iterator it2=ans[v[x]].begin();it2!=ans[v[x]].end();++it2)
			{
				if(it1->first+it2->first<=m)
				{
					ans[0][it1->first+it2->first]=max(ans[0][it1->first+it2->first],it1->second+it2->second);
				}
			}
		}
		ans[v[x]]=ans[0];
	}
	ans[v[x]][1]=max(ans[v[x]][1],b[x]);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=n;++i)
	{
		int p,x;
		cin>>p>>x;
		a[p].push_back(i);
		b[i]=x;
		if(p==0)
			pp=i;
	}
	dfs(pp,0);
	cout<<ans[v[pp]][m]<<endl;
	return 0;
}

void fp()
{
#ifndef OLYMP
	freopen("d.in","r",stdin);
	freopen("d.out","w",stdout);
#endif
}
void sp()
{
#ifdef OLYMP
	system("pause");
#endif
}

Compilation message

biochips.cpp:1:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker,"/STACK:200000000")
 
biochips.cpp: In function 'void dfs(int, int)':
biochips.cpp:29:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<a[x].size();++i)
              ~^~~~~~~~~~~~
biochips.cpp:43:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1;i<a[x].size();++i)
              ~^~~~~~~~~~~~
biochips.cpp: In function 'void fp()':
biochips.cpp:82:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("d.in","r",stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~
biochips.cpp:83:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("d.out","w",stdout);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 14464 KB Output is correct
2 Correct 9 ms 14464 KB Output is correct
3 Correct 18 ms 14464 KB Output is correct
4 Correct 49 ms 15736 KB Output is correct
5 Correct 66 ms 15996 KB Output is correct
6 Correct 96 ms 16120 KB Output is correct
7 Execution timed out 2062 ms 29944 KB Time limit exceeded
8 Halted 0 ms 0 KB -