#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <string>
#include <set>
#include <utility>
#define all(a) (a).begin(), (a).end()
#define allr(a) (a).rbegin(), (a).rend()
#define ll long long
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define fr1(i, a, b) for (ll i = a - 1; i >= b; i--)
#define fi first
#define se second
#define mp(j, k) make_pair(j, k)
#define pb(x) push_back(x)
#define pbp(x, y) push_back({x, y})
#define in(x) insert(x)
#define vec vector<ll>
#define vecv vector<vector<ll> >
#define veb vector<bool>
#define vecp vector<pair<ll,ll>>
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define ac 1e-7
#define fauto(a) \
for (auto i : a) \
cout << i << " ";
#define fautop(a) \
for (auto i : a) \
cout << i.fi << " " << i.se << endl;
using namespace std;
int query(vector < int > islands);
vector<int> ini;
vector<vector<int> > adj;
ll t;
void dfs(int node, int parent)
{
ini[t++] = node + 1;
for(int e : adj[node])
{
if(e != parent)
dfs(e, node);
}
}
int binary(int a, int b)
{
while(a + 1 < b)
{
int mid = (a + b) / 2;
vector<int> ax(ini.begin() + a, ini.begin() + mid + 1);
if(query(ax))
{
b = mid;
}
else
{
a = mid;
}
}
return ini[b];
}
int findEgg(int N, vector < pair < int, int > > bridges)
{
adj.resize(N);
fr(i, 0, N) adj[i].clear();
for(auto &p : bridges)
{
ll u = p.fi;
ll v = p.se;
u--, v--;
adj[u].pb(v);
adj[v].pb(u);
}
ini.resize(N);
t = 0;
dfs(0, -1);
binary(-1, N - 1);
ini.clear();
}
Compilation message (stderr)
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:100:1: warning: no return statement in function returning non-void [-Wreturn-type]
100 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |