답안 #115936

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
115936 2019-06-10T01:40:37 Z puppies_and_rainbows Easter Eggs (info1cup17_eastereggs) C++14
0 / 100
5 ms 768 KB
#include <bits/stdc++.h>
#include "grader.h"
 
using namespace std;
 
int size[1005];
int fa[1005];
bool used[1005];
vector<int> ask;
vector<int> adj[1005];
//bool query(vector<int> dwsad)
//{
//	return true;
//}
 
void dfs(int node, int fat)
{
	ask.push_back(node);
	size[node]++;
	for(auto i:adj[node])
	{
		if(i==fat) continue;
		dfs(i, node);
		size[node]+=size[i];
		fa[i]=node;
	}
}
 
void dfs1(int node, int fat)
{
	ask.push_back(node);
	for(auto i:adj[node])
	{
		if(i==fat) continue;
		if(used[i]) continue;
		dfs1(i, node);
	}
}
 
int findEgg (int N, vector < pair < int, int > > bridges)
{
	ask.clear();
	for(auto i:bridges)
	{
		adj[i.first].push_back(i.second);
		adj[i.second].push_back(i.first);
	}
	dfs(1,1);
	int n=N;
	int left=n;
	while(true)
	{
		ask.clear();
		if(left==1)
		{
			for(int i=1; i<=n; i++)
			{
				if(!used[i]) return i;
			}
		}
		int maxsize=0, take=0;
		for(int i=1; i<=n; i++)
		{
			if(!used[i]&&size[i]<=left/2&&size[i]>maxsize)
			{
				maxsize=size[i];
				take=i;
			}
		}
		dfs1(take,take);
		if(query(ask)==0)
		{
			for(auto i:ask)
			{
				used[i]=true;
			}
			int cac=fa[take];
			while(cac!=0)
			{
				size[cac]-=size[take];
				cac=fa[cac];
			}
		}
		else
		{
			int lay[1000];
			memset(lay, 0, sizeof(lay));
			for(auto i:ask)
			{
				lay[i]=1;
			}
			for(int i=1; i<=n; i++)
			{
				if(!lay[i])
				used[i]=true;
				else
				used[i]=false;
			}
		}
		left=0;
		for(int i=1; i<=n; i++)
		{
			if(!used[i])
			{
				left++;
			}
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -