#include <vector>
#include<bits/stdc++.h>
#define f first
#define s second
#define ent '\n'
using namespace std;
typedef long long ll;
const int mx=2e5+12;
vector<int> g[mx];
int was[mx][mx];
bool are_connected(std::vector<int> A, std::vector<int> B);
int ask(int a,int b){
if(!was[a][b]){
was[a][b]=was[b][a]=(int)are_connected({a},{b})+1;
}
return was[a][b]-1;
}
std::vector<int> longest_trip(int n, int d){
vector<int> ans;
for(int i=0;i<n;i++){
g[i].clear();
for(int j=0;j<n;j++){
was[i][j]=0;
}
}
srand(time(0));
vector<int> t;
for(int i=0;i<n;i++){
g[i].push_back(i);
t.push_back(i);
}
while(t.size()>2){
int a=t[0],b=t[1],c=t[2];
vector<pair<int,int>> d;
d.push_back({a,b});
d.push_back({a,c});
d.push_back({b,c});
random_shuffle(d.begin(),d.end());
int v,u;
if(ask(d[0].f,d[0].s)){
v=d[0].f,u=d[0].s;
}
else if(ask(d[1].f,d[1].s)){
v=d[1].f,u=d[1].s;
}
else{
v=d[2].f,u=d[2].s;
}
reverse(g[v].begin(),g[v].end());
for(int x:g[u]){
g[v].push_back(x);
}
g[u].clear();
int x=g[v][0];
if(x!=v){
for(int to:g[v]){
g[x].push_back(to);
}
g[v].clear();
}
t.clear();
for(int i=0;i<n;i++){
if((int)g[i].size()>0){
t.push_back(i);
}
}
}
int a=t[0],b=t[1];
if((int)g[a].size()>(int)g[b].size()){
return g[a];
}
else{
return g[b];
}
}
Compilation message
/tmp/cc6ZoSsw.o: in function `__tcf_0':
longesttrip.cpp:(.text+0x9): relocation truncated to fit: R_X86_64_PC32 against symbol `g' defined in .bss section in /tmp/cc6ZoSsw.o
/tmp/cc6ZoSsw.o: in function `longest_trip(int, int)':
longesttrip.cpp:(.text+0x236): relocation truncated to fit: R_X86_64_PC32 against symbol `g' defined in .bss section in /tmp/cc6ZoSsw.o
longesttrip.cpp:(.text+0x291): relocation truncated to fit: R_X86_64_PC32 against symbol `g' defined in .bss section in /tmp/cc6ZoSsw.o
longesttrip.cpp:(.text+0x985): relocation truncated to fit: R_X86_64_PC32 against symbol `g' defined in .bss section in /tmp/cc6ZoSsw.o
/tmp/cc6ZoSsw.o: in function `_GLOBAL__sub_I_g':
longesttrip.cpp:(.text.startup+0xb): relocation truncated to fit: R_X86_64_PC32 against `.bss'
longesttrip.cpp:(.text.startup+0x25): relocation truncated to fit: R_X86_64_PC32 against `.bss'
longesttrip.cpp:(.text.startup+0x31): relocation truncated to fit: R_X86_64_PC32 against symbol `g' defined in .bss section in /tmp/cc6ZoSsw.o
/usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a(vterminate.o): in function `__gnu_cxx::__verbose_terminate_handler()':
(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x1e): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZZN9__gnu_cxx27__verbose_terminate_handlerEvE11terminating'
(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x2b): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZZN9__gnu_cxx27__verbose_terminate_handlerEvE11terminating'
/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax
collect2: error: ld returned 1 exit status