답안 #919074

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
919074 2024-01-31T08:08:45 Z penguin133 Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
12 ms 1272 KB
#include <bits/stdc++.h>
using namespace std;
 #include "grader.h"
//#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int S[1005], back[1005], c = 1;
vector <int> adj[1005];
 
void dfs(int x, int par){
	S[x] = c++;
	for(auto i : adj[x])if(i != par)dfs(i, x);
}
 
int findEgg (int N, vector < pair < int, int > > bridges)
{
	c = 1;
    for(int i = 1; i <= N; i++)adj[i].clear();
    for(auto [i, j] : bridges)adj[i].push_back(j), adj[j].push_back(i);
    dfs(1, -1);
    for(int i = 1; i <= N; i++)back[S[i]] = i;
    int lo = 1, hi = N - 1, ans = hi + 1;
  
    while(lo <= hi){
		int mid = (lo + hi) >> 1;
		vector <int> v;
		for(int i = 1; i <= mid; i++)v.push_back(back[i]);
		if(query(v))ans = mid, hi = mid - 1;
		else lo = mid + 1;
	}
    return back[ans];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Number of queries: 4
2 Correct 1 ms 344 KB Number of queries: 4
3 Correct 1 ms 344 KB Number of queries: 4
4 Correct 1 ms 344 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 492 KB Number of queries: 8
2 Correct 8 ms 768 KB Number of queries: 9
3 Correct 12 ms 760 KB Number of queries: 9
4 Correct 10 ms 1272 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 776 KB Number of queries: 9
2 Correct 9 ms 772 KB Number of queries: 9
3 Correct 11 ms 756 KB Number of queries: 9
4 Correct 12 ms 1028 KB Number of queries: 9