답안 #91814

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91814 2018-12-30T07:34:53 Z SamAnd 바이오칩 (IZhO12_biochips) C++17
0 / 100
2000 ms 30892 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()
{
	//fp();
	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:83: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:84: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);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14540 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 14 ms 14456 KB Output is correct
4 Correct 41 ms 15800 KB Output is correct
5 Correct 64 ms 15992 KB Output is correct
6 Correct 79 ms 16120 KB Output is correct
7 Execution timed out 2082 ms 30892 KB Time limit exceeded
8 Halted 0 ms 0 KB -