답안 #115958

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
115958 2019-06-10T03:36:06 Z nhimnam120 Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
23 ms 396 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

vector<int> ask;
vector<int> adj[1005];
bool used[1005];
bool wrong[1005];
long long size=0;
long long cnt=0;
void dfs(long long node, long long par){
	if(cnt==size/2) return;
	if(used[node]==0) 
	{
		cnt++;
	}
	ask.push_back(node);
	for(auto i : adj[node]){
		if(wrong[i]!=0||i==par) continue;
		dfs(i,node);
	}
}
int findEgg (int N, vector < pair < int, int > > bridges)
{
    ask.clear();
	memset(used,0,sizeof(used));
	memset(wrong,0,sizeof(wrong));
	for(int i=1;i<=N;i++){
		adj[i].clear();
	}
	size=N;
	for(auto i:bridges){
		adj[i.first].push_back(i.second);
		adj[i.second].push_back(i.first);
	}
	while(true){
		ask.clear();
		if(size==1){
			for(int i=1;i<=N;i++){
				if(used[i]==0&&wrong[i]==0){
					return i;
				}
			}
		}
		else{
			cnt=0;
			dfs(1,1);
			if(query(ask)==1){
				size=cnt;
				bool vs[1001];
				memset(vs,0,sizeof(vs));
				for(auto i:ask){
					vs[i]=1;
				}
				for(int i=1;i<=N;i++){
					if(vs[i]==0){
						wrong[i]=true;
					}
				}
			}
			else{
				size=size-cnt;
				for(auto i:ask){
					used[i]=true;
				}
			}
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Number of queries: 4
2 Correct 2 ms 256 KB Number of queries: 4
3 Correct 2 ms 256 KB Number of queries: 4
4 Correct 3 ms 256 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Number of queries: 8
2 Correct 11 ms 256 KB Number of queries: 9
3 Correct 18 ms 256 KB Number of queries: 9
4 Correct 23 ms 384 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 396 KB Number of queries: 9
2 Correct 18 ms 384 KB Number of queries: 9
3 Correct 17 ms 384 KB Number of queries: 9
4 Correct 18 ms 256 KB Number of queries: 9