#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using dll = deque <ll>;
using vi = vector <int>;
const ll MAXN = 256+16;
vll adj[MAXN];
bool mat[MAXN][MAXN];
ll comp[MAXN];
void dfs (ll u, ll col, ll &sz) {
if (comp[u]) return;
comp[u] = col;
sz++;
for (ll v : adj[u]) {
dfs(v, col, sz);
}
}
vi longest_trip (int n, int d) {
fill(adj, adj+n+5, vll({}));
fill(comp, comp+n+5, 0);
for (ll u = 0; u < n; u++) {
mat[u][u] = false;
for (ll v = u+1; v < n; v++) {
if (are_connected(vi({ int(u) }), vi({ int(v) }))) {
adj[u].push_back(v);
adj[v].push_back(u);
mat[u][v] = true;
mat[v][u] = true;
} else {
mat[u][v] = false;
mat[v][u] = false;
}
}
}
ll c = 1;
vll sz;
for (ll u = 0; u < n; u++) {
if (comp[u]) continue;
sz.push_back(0);
dfs(u, c++, sz.back());
}
if (c == 2) {
dll dq;
dq.push_back(0);
vector <char> vis(n, false);
vis[0] = true;
for (ll v = 0; v < n; v++) {
if (mat[0][v]) {
vis[v] = true;
dq.push_back(v);
break;
}
}
assert(dq.size() == 2);
for (ll u = 0; u < n; u++) {
if (vis[u]) continue;
vis[u] = true;
if (mat[u][dq.front()]) {
dq.push_front(u);
} else if (mat[u][dq.back()]) {
dq.push_back(u);
}
}
vi ans(dq.begin(), dq.end());
return ans;
} else if (c == 3) {
assert(sz.size() == 2);
if (sz[0] > sz[1]) {
vi ans;
for (ll u = 0; u < n; u++) {
if (comp[u] == 1) {
ans.push_back(u);
}
}
} else {
vi ans;
for (ll u = 0; u < n; u++) {
if (comp[u] == 2) {
ans.push_back(u);
}
}
}
return ans;
}
}
Compilation message
longesttrip.cpp: In function 'vi longest_trip(int, int)':
longesttrip.cpp:88:16: error: 'ans' was not declared in this scope; did you mean 'abs'?
88 | return ans;
| ^~~
| abs