#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
vector<int>v;
vector<pair<int,int>>l;
bool ok[520];
void constructie(int poz,int n)
{
int nr=0;
while(++nr<n)
{
ok[poz]=true;
v.push_back(poz);
if(ok[l[poz].first]==true)
poz=l[poz].second;
else
poz=l[poz].first;
}
v.push_back(poz);
return;
}
//int query(vector < int > islands);
int findEgg(int N, vector < pair < int, int > > bridges)
{
v.clear();
l.clear();
int nra[520]={0};
l.resize(N+5);
v.resize(N+5);
for(int i=1;i<=N;++i)
ok[i]=false;
for(auto x:bridges)
{
++nra[x.first];
++nra[x.second];
if(nra[x.first]==1)
l[x.first].first=x.second;
else
l[x.first].second=x.second;
if(nra[x.second]==1)
l[x.second].first=x.first;
else
l[x.second].second=x.first;
}
for(int i=1;i<=N;++i)
{
if(nra[i]==0)
constructie(i,N);
break;
}
int b=0,e=N-1;
while(b<=e)
{
int m=(b+e)/2;
vector<int>q;
q.resize(0);
for(int x=b;x<=e;++x)
q.push_back(v[x]);
if(query(q))
e=m-1;
else
b=m+1;
q.clear();
}
return v[b];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
328 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
456 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
456 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |