#include <cstdio>
#include <vector>
#include <algorithm>
#include "grader.h"
using namespace std;
vector <int> w[600];
vector <int> eul;
int p[1200];
int poz;
int findd (int x , int dr){
int st,mid;
st = 1;
while (st<=dr){
mid = ( st + dr )/2;
if (p[mid] == x)
return mid;
else if (p[mid]<x)
st = mid + 1;
else dr = mid - 1;
}
return 0;
}
void euler (int nod ,int tata){
int vecin;
eul.push_back(nod);
for (int i = 0 ; i < w[nod].size() ; i++){
vecin = w[nod][i];
if (vecin!=tata){
euler (vecin,nod);
eul.push_back(nod);
}
}
}
int findEgg (int n , vector <pair <int,int> > v){
int st,dr,mid,sol,x,y,elem;
vector <int> islands;
for (int i=1;i<=n;i++)
w[i].clear();
elem = 0;
for (int i=0;i<v.size();i++){
x = v[i].first;
y = v[i].second;
p[++elem] = x;
p[++elem] = y;
}
sort (p+1,p+elem+1);
int elem2=0;
for (int i=1;i<=elem;i++)
if (p[i]!=p[elem2] || !elem2)
p[++elem2] = p[i];
for (int i=0;i<v.size();i++){
x = findd(v[i].first,elem);
y = findd(v[i].second,elem);
w[x].push_back(y);
w[y].push_back(x);
}
eul.clear();
euler(1,0); /// eul e un vector cu parc euler , dim 2*n
st = 0;
dr = eul.size()-1;
while (st<dr){
mid = (st + dr)/2;
/// iei de la st la mid
islands.clear();
for (int i=st;i<=mid;i++)
islands.push_back(eul[i]);
sol = query(islands);
if (sol == 0)
st = mid + 1;
else dr = mid;
}
return p[eul[st]];
}
Compilation message
eastereggs.cpp: In function 'void euler(int, int)':
eastereggs.cpp:27:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0 ; i < w[nod].size() ; i++){
~~^~~~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:42:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<v.size();i++){
~^~~~~~~~~
eastereggs.cpp:55:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<v.size();i++){
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |