답안 #61643

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61643 2018-07-26T08:43:06 Z huynhsmd Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
46 ms 3056 KB
#include<bits/stdc++.h>
#include "grader.h"

#define pb push_back
#define fi first
#define se second
using namespace std;

typedef pair <int , int > ii;
const int N = 1e5 + 5;
int arr[N], cnt = 0;
vector < int > adj[N], ask;

void dfs(int u, int p){
	arr[++cnt] = u;
	for(int v : adj[u]) if(v != p) dfs(v, u);
}
int findEgg(int N, vector < ii > bridges){
	int n = N;
	for(int i = 1; i <= n; ++ i) adj[i].clear();
	for(ii i : bridges) adj[i.fi].pb(i.se), adj[i.se].pb(i.fi);
	dfs(1, 1);
	int l = 1, r = n, res;
	while(l < r){
		int mid = l + r >> 1;
		ask.clear();
		for(int i = 1; i <= mid; ++ i) ask.pb(arr[i]);
		if(query(ask)) r = mid;
		else l = mid + 1;
	}
	return arr[l];
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:25:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = l + r >> 1;
             ~~^~~
eastereggs.cpp:23:20: warning: unused variable 'res' [-Wunused-variable]
  int l = 1, r = n, res;
                    ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2552 KB Number of queries: 4
2 Correct 8 ms 2740 KB Number of queries: 4
3 Correct 7 ms 2740 KB Number of queries: 4
4 Correct 6 ms 2792 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 2792 KB Number of queries: 8
2 Correct 31 ms 2852 KB Number of queries: 9
3 Correct 41 ms 2896 KB Number of queries: 9
4 Correct 46 ms 2932 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 2988 KB Number of queries: 9
2 Correct 24 ms 2988 KB Number of queries: 9
3 Correct 41 ms 2988 KB Number of queries: 9
4 Correct 36 ms 3056 KB Number of queries: 9