#include <bits/stdc++.h>
#include "grader.h"
#define pb push_back
using namespace std;
vector <int> v[605];
int dp[605],mx,l,f[605],N,ANS;
priority_queue <pair<int,int> > pq;
void dfs(int x,int par){
// cout<<"node = "<<x<<"\n";
for (int j=0;j<v[x].size();j++){
int to = v[x][j];
if (to == par) continue;
dp[to] = dp[x] + 1;
dfs(to,x);
}
if (dp[x] > mx)
mx=dp[x],l = x;
}
void clear(int n){
while(pq.size())
pq.pop();
for (int i = 1; i <= n; i++)
v[i].clear(),dp[i] = 0,f[i] = 0;
}
void go(int n, vector < pair < int, int > > vec,vector <int> vert){
if (vert.size() == 1) {
ANS= vert[0];
return;
}
for (int i = 0; i < n - 1; i++){
int a = vec[i].first,b = vec[i].second;
v[a].pb(b),v[b].pb(a);
}
dp[vert[0]] = 1;
mx = 1;
l = vert[0];
dfs(vert[0],vert[0]);
vector <int> q; q.clear();
while(pq.size())
pq.pop();
pq.push({mx,l});
while(pq.size()){
int x = pq.top().second;
pq.pop();
if (f[x] == 1) continue;
f[x] = 1,q.pb(x);
if (q.size() == n/2) break;
for (int j = 0; j<v[x].size(); j++){
int to = v[x][j];
if (!f[to]) pq.push({dp[to],to});
}
}
if (query(q) == 1){
int m=0,raod=0;
vector <pair<int,int> > edges; edges.clear();
for (int i=0;i<vec.size();i++){
int a = vec[i].first,b = vec[i].second;
if (f[a] && f[b]) edges.pb({a,b});
}
vector <int> newv; newv.clear();
for (int i = 0; i < vert.size(); i++)
if (f[vert[i]]) newv.pb(vert[i]);
clear(N);
go(newv.size(), edges, newv);
}
else{
vector <pair<int,int> > edges; edges.clear();
int m = 0,raod=0;
for (int i=0;i<vec.size();i++){
int a = vec[i].first,b = vec[i].second;
if (!f[a] && !f[b]) edges.pb({a,b});
}
vector <int> newv; newv.clear();
for (int i = 0; i < vert.size(); i++)
if (!f[vert[i]]) newv.pb(vert[i]);
clear(N);
go(newv.size(), edges, newv);
}
}
int findEgg (int n, vector < pair < int, int > > vec){
N = n;
vector <int> vert; vert.clear();
for (int i=1;i<=n;i++)
vert.pb(i);
go(n,vec,vert);
return ANS;
}
Compilation message
eastereggs.cpp: In function 'void dfs(int, int)':
eastereggs.cpp:12:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for (int j=0;j<v[x].size();j++){
| ~^~~~~~~~~~~~
eastereggs.cpp: In function 'void go(int, std::vector<std::pair<int, int> >, std::vector<int>)':
eastereggs.cpp:56:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
56 | if (q.size() == n/2) break;
| ~~~~~~~~~^~~~~~
eastereggs.cpp:57:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int j = 0; j<v[x].size(); j++){
| ~^~~~~~~~~~~~
eastereggs.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int i=0;i<vec.size();i++){
| ~^~~~~~~~~~~
eastereggs.cpp:71:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (int i = 0; i < vert.size(); i++)
| ~~^~~~~~~~~~~~~
eastereggs.cpp:64:13: warning: unused variable 'm' [-Wunused-variable]
64 | int m=0,raod=0;
| ^
eastereggs.cpp:64:17: warning: unused variable 'raod' [-Wunused-variable]
64 | int m=0,raod=0;
| ^~~~
eastereggs.cpp:80:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for (int i=0;i<vec.size();i++){
| ~^~~~~~~~~~~
eastereggs.cpp:85:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for (int i = 0; i < vert.size(); i++)
| ~~^~~~~~~~~~~~~
eastereggs.cpp:79:13: warning: unused variable 'm' [-Wunused-variable]
79 | int m = 0,raod=0;
| ^
eastereggs.cpp:79:19: warning: unused variable 'raod' [-Wunused-variable]
79 | int m = 0,raod=0;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
200 KB |
Number of queries: 4 |
2 |
Runtime error |
1 ms |
456 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
328 KB |
Number of queries: 8 |
2 |
Runtime error |
1 ms |
456 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
380 KB |
Number of queries: 9 |
2 |
Runtime error |
1 ms |
456 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |