This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "island.h"
using namespace std;
int N;
vector<int> g[305];
int d[305][305];
int ua[305];
vector<int> ug[305];
void dfs(int x, int par, int root, int depth){
d[root][x] = depth;
d[x][root] = depth;
for (int tgt : g[x]){
if (tgt == par) continue;
dfs(tgt,x,root,depth+1);
}
}
int f(int x){
if (ua[x] == x) return x;
return ua[x] = f(ua[x]);
}
// "All neighbours known"
bool ann[305];
int gi[305];
void merge(int x, int y){
int fx = f(x);
int fy = f(y);
if (f(x) == f(y)){
return;
}
if (ug[fx].size() > ug[fy].size()){
swap(fx,fy);
swap(x,y);
}
g[x].push_back(y);
g[y].push_back(x);
answer(x,y);
if (g[x].size() == N-1){
ann[x] = true;
}
if (g[y].size() == N-1){
ann[y] = true;
}
for (int tgt : ug[fx]){
ug[fy].push_back(tgt);
dfs(tgt,-1,tgt,0);
}
ua[fx] = fy;
ug[fx].clear();
}
void solve(int n, int L) {
N = n;
for (int i = 1; i <= N; i++){
ug[i].push_back(i);
ua[i] = i;
gi[i] = 1;
}
for (int i = N; i > 1; i--){
int ret = query(i,1);
merge(i,ret);
}
ann[1] = true;
for (int cur_ann = 1; cur_ann < N; cur_ann++){
for (int i = 1; i <= cur_ann; i++){
for (int j: g[i]){
if (ann[j]) continue;
bool can_expand = true;
for (int tgt: g[j]){
if (!ann[tgt]) {
can_expand = false;
break;
}
}
if (can_expand){
int ret = query(j,++gi[j]);
if (d[ret][j] == 2){
ann[j] = true;
}
else{
merge(ret,j);
}
}
}
}
ann[cur_ann+1] = true;
}
// int variable_example = query(1, 1);
// for (int i = 2; i <= N; i++) {
// answer(1, i);
// }
}
Compilation message (stderr)
island.cpp: In function 'void merge(int, int)':
island.cpp:50:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
50 | if (g[x].size() == N-1){
| ~~~~~~~~~~~~^~~~~~
island.cpp:53:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
53 | if (g[y].size() == N-1){
| ~~~~~~~~~~~~^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |