#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
#define MAX_N 513
vector <int> adj[MAX_N] ,active ,Set;
int SZ;
void dfs(int u ,int p=-1){
if(!SZ)
return;
Set.push_back(u);
if(find(active.begin() ,active.end() ,u) != active.end())
SZ--;
for(int&v : adj[u]) if(v != p)
dfs(v ,u);
}
vector <int> findSet(int sz){
SZ = sz;
Set.clear();
dfs(1);
return Set;
}
int findEgg (int N, vector < pair < int, int > > bridges){
active.clear();
for(int i=0; i<=N; i++)
adj[i].clear();
for(auto&e : bridges)
adj[e.first].push_back(e.second),
adj[e.second].push_back(e.first);
active.resize(N);
iota(active.begin() ,active.end() ,1);
while(active.size() > 1){
vector <int> vs = findSet(((int)active.size())/2);
if(query(vs)){
vector <int> nv;
for(int&v : vs)
if(find(active.begin() ,active.end() ,v) != active.end())
nv.push_back(v);
active = nv;
}else{
for(int&v : vs)
if(find(active.begin() ,active.end() ,v) != active.end())
active.erase(find(active.begin() ,active.end() ,v));
}
}
return active.front();
}
# |
결과 |
실행 시간 |
메모리 |
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 |
384 KB |
Number of queries: 4 |
4 |
Correct |
5 ms |
384 KB |
Number of queries: 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
384 KB |
Number of queries: 8 |
2 |
Correct |
28 ms |
384 KB |
Number of queries: 9 |
3 |
Correct |
32 ms |
384 KB |
Number of queries: 9 |
4 |
Correct |
34 ms |
384 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
384 KB |
Number of queries: 9 |
2 |
Correct |
27 ms |
384 KB |
Number of queries: 9 |
3 |
Correct |
29 ms |
384 KB |
Number of queries: 9 |
4 |
Correct |
29 ms |
384 KB |
Number of queries: 9 |