답안 #243017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
243017 2020-06-30T07:41:16 Z daongocha Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
23 ms 384 KB
#include <bits/stdc++.h>
#include "grader.h"

#define For(i,a,b) for (int i = a; i <= (b); i++)
#define For2(i,a,b) for (int i = a; i >= (b); i--)

#define pii pair<int, int>
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define INF 2147483647
#define EPS 1e-9
#define fi first
#define se second
//f#define FILEOPEN

using namespace std;

vector<int> path[515];
vector<int> passed;

void dfs(int u, int prev) { 
	passed.pb(u);
	for (int v: path[u]) {
		if (v == prev) continue;
		dfs(v, u);
	}
}

int findEgg(int n, vector<pii> bridges) {
	For(i,1,n) path[i].clear();
	for (pii a: bridges) {
		path[a.fi].pb(a.se);
		path[a.se].pb(a.fi);
	}
	passed.clear(); passed.pb(0);
	dfs(1, 1);
	int l = 1, r = n;
	while (l < r) {
		int mid = (l + r) / 2;
		vector<int> a;
		For(i,1,mid) a.pb(passed[i]);
		if (query(a)) r = mid;
		else l = mid + 1;
	}
	return passed[l];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Number of queries: 4
2 Correct 5 ms 384 KB Number of queries: 4
3 Correct 5 ms 256 KB Number of queries: 4
4 Correct 5 ms 384 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 384 KB Number of queries: 8
2 Correct 17 ms 384 KB Number of queries: 9
3 Correct 22 ms 384 KB Number of queries: 9
4 Correct 20 ms 384 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 384 KB Number of queries: 9
2 Correct 19 ms 384 KB Number of queries: 9
3 Correct 23 ms 384 KB Number of queries: 9
4 Correct 21 ms 384 KB Number of queries: 9