답안 #115938

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
115938 2019-06-10T02:01:28 Z puppies_and_rainbows Easter Eggs (info1cup17_eastereggs) C++14
10 / 100
15 ms 640 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)
{
	memset(size, 0, sizeof(size));
	memset(fa, 0, sizeof(fa));
	memset(used, 0, sizeof(used));
	for(int i=1; i<=512; i++)
	{
		adj[i].clear();
	}
	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)
	{
//		cout << left << endl;
		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;
			}
		}
//		cout<<take<<" "<<maxsize<<endl;
		dfs1(take,fa[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));
//			cout << endl;
			for(auto i:ask)
			{
//				cout << i << " ";
				lay[i]=1;
			}
//			cout << endl;
			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 Correct 2 ms 256 KB Number of queries: 4
2 Incorrect 3 ms 256 KB Number of queries: 5
3 Incorrect 3 ms 412 KB Number of queries: 12
4 Incorrect 4 ms 256 KB Number of queries: 15
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Number of queries: 8
2 Incorrect 8 ms 256 KB Number of queries: 14
3 Incorrect 10 ms 256 KB Number of queries: 28
4 Runtime error 4 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Number of queries: 9
2 Incorrect 7 ms 284 KB Number of queries: 13
3 Incorrect 15 ms 412 KB Number of queries: 28
4 Runtime error 3 ms 560 KB Execution killed with signal 11 (could be triggered by violating memory limits)