#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
typedef long long ll ;
const ll mk = 100005;
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
vector <int> g[mk] ,now_ ,cur_set;
int mx_size;
void dfs(int u ,int p=-1){
if(!mx_size)
return;
cur_set.push_back(u);
if(find(now_.begin() ,now_.end() ,u) != now_.end())
mx_size--;
for(int i = 0 ; i < g[u].size(); i++) {
int v = g[u][i];
if(v != p) dfs(v ,u);
}
}
vector <int> findSet(int sz){
mx_size = sz;
cur_set.clear();
dfs(1);
return cur_set;
}
int findEgg (int N, vector < pair < int, int > > bridges){
now_.clear();
for(int i=0; i<=mk; i++)
g[i].clear();
for(int i = 0 ; i < N - 1; i++) {
g[bridges[i].fi].push_back(bridges[i].se);
g[bridges[i].se].push_back(bridges[i].fi);
}
now_.resize(N);
iota(now_.begin() ,now_.end() ,1);
while(now_.size() > 1){
vector <int> visit = findSet(((int)now_.size())/2); // divide the previous size
if(query(visit)){
vector <int> nv;
for(int i = 0 ; i < visit.size(); i++ )
{
int v = visit[i];
if(find(now_.begin() ,now_.end() ,v) != now_.end())
{
nv.push_back(v); // all those nodes in the previous subset
}
}
now_ = nv;
}
else{
for(int i =0; i < visit.size() ; i++)
{
int v = visit[i];
if(find(now_.begin() ,now_.end() ,v) != now_.end())
{
now_.erase(find(now_.begin() ,now_.end() ,v));
}
}
}
}
return now_.front();
}
Compilation message
eastereggs.cpp: In function 'void dfs(int, int)':
eastereggs.cpp:24:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0 ; i < g[u].size(); i++) {
~~^~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:52:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0 ; i < visit.size(); i++ )
~~^~~~~~~~~~~~~~
eastereggs.cpp:63:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i =0; i < visit.size() ; i++)
~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
5120 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
5220 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
5248 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |