답안 #97703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97703 2019-02-17T18:18:47 Z KLPP Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
23 ms 476 KB
#include <bits/stdc++.h>
#include "grader.h"
 
using namespace std;
typedef pair<int,int> pii;
vector<int> nei[1000];
vector<int> order;

void DFS(int u,int last){
	order.push_back(u);
	for(int i=0;i<nei[u].size();i++){
		int v=nei[u][i];
		if(v!=last){
			DFS(v,u);
		}
	}
}
int findEgg (int N, vector < pair < int, int > > bridges)
{
	order.clear();
	int n=N;
	for(int i=0;i<n;i++)nei[i].clear();
	for(int i=0;i<bridges.size();i++){
		nei[bridges[i].first-1].push_back(bridges[i].second-1);
		nei[bridges[i].second-1].push_back(bridges[i].first-1);
	}
	DFS(0,-1);
	/*for(int i=0;i<n;i++){
		vector<int> v;
		v.push_back(i+1);
		if(query(v))return i+1;
	}*/
	//for(int i=0;i<n;i++)cout<<dist[i].second<<endl;
	int lo=0;
	int hi=n;
	while(hi-lo>1){
		int mid=(hi+lo)/2;
		vector<int> v;
		for(int i=0;i<mid;i++)v.push_back(order[i]+1);
		if(query(v)){
			hi=mid;
		}else lo=mid;
	}
	/*for(int i=0;i<n;i++){
		vector<int> v;
		v.push_back(i+1);
		if(query(v))return i+1;
	}*/
	return order[lo]+1;
}

Compilation message

eastereggs.cpp: In function 'void DFS(int, int)':
eastereggs.cpp:11:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<nei[u].size();i++){
              ~^~~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:23:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<bridges.size();i++){
              ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Number of queries: 4
2 Correct 0 ms 256 KB Number of queries: 4
3 Correct 3 ms 384 KB Number of queries: 4
4 Correct 3 ms 384 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Number of queries: 8
2 Correct 15 ms 256 KB Number of queries: 9
3 Correct 23 ms 256 KB Number of queries: 9
4 Correct 19 ms 256 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 476 KB Number of queries: 9
2 Correct 13 ms 456 KB Number of queries: 9
3 Correct 14 ms 376 KB Number of queries: 9
4 Correct 19 ms 384 KB Number of queries: 9