답안 #1057179

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057179 2024-08-13T14:46:25 Z Drifter24 Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
12 ms 616 KB
#include <bits/stdc++.h>
using namespace std;

int query(vector < int > islands);
void dfs(int v, int p, vector<vector<int>>& adj, vector<int>& ans){
	ans.push_back(v);
	for(int u:adj[v]){
		if(u==p)continue;
		dfs(u, v, adj, ans);
	}
}

int findEgg(int N, vector < pair < int, int > > bridges){
	vector<int> ans;
	vector<vector<int>> adj(N+1, vector<int>());
	for(auto x:bridges){
		adj[x.first].push_back(x.second);
		adj[x.second].push_back(x.first);
	}
	dfs(1, 0, adj, ans);
	int l=0,r=N-1;
	while(r!=l){
		int m=(r+l+1)/2;
		if(query(vector<int>(ans.begin(), ans.begin() + m)))r=m-1;
		else l=m;
	}
	return ans[l];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Number of queries: 4
2 Correct 0 ms 344 KB Number of queries: 4
3 Correct 0 ms 344 KB Number of queries: 4
4 Correct 0 ms 344 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 600 KB Number of queries: 8
2 Correct 6 ms 340 KB Number of queries: 9
3 Correct 12 ms 500 KB Number of queries: 9
4 Correct 8 ms 344 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 616 KB Number of queries: 9
2 Correct 8 ms 600 KB Number of queries: 9
3 Correct 8 ms 344 KB Number of queries: 9
4 Correct 11 ms 488 KB Number of queries: 9