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 "islands.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
using pii=pair<int,int>;
int n,m;
map<pii,int>mp;
const int lim=2e5+100;
bool vis[lim];
vector<int>v[lim];
bool foundloop=0;
void dfs(int node,int par){
  vis[node]=1;
  for(int j:v[node]){
    if(vis[j]){
      foundloop=1;
      return;
    }
    dfs(j,node);
    if(foundloop)return;
  }
}
std::variant<bool, std::vector<int>> find_journey(
    int N, int M, std::vector<int> U, std::vector<int> V) {
  n=N,m=M;
  if(n==2){
    vector<int>go,come;
    for(int i=0;i<m;i++){
      if(!U[i])go.pb(i);
      else come.pb(i);
    }
    if(come.size()&&1<go.size()){
      return vector<int>{go[0],come[0],go[1],go[0],come[0],go[1]};
    }
    return false;
  }
  for(int i=0;i<m;i++){
    mp[{U[i],V[i]}]=i;
  }
  if(mp.size()==n*(n-1)){
    return vector<int>{mp[{0,1}],mp[{1,2}],mp[{2,1}],mp[{0,1}],mp[{0,2}],mp[{1,2}],mp[{2,1}],mp[{0,2}]};
  }
  dfs(0,-1);
  if(foundloop)return true;
  return false;
  bool flag=1;
  for(int i=0;i<m;i+=2){
    if(U[i]==V[i+1])flag=0;
  }
  if(!flag){
    //first case
  }
  return false;
}
Compilation message (stderr)
islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:51:15: warning: comparison of integer expressions of different signedness: 'std::map<std::pair<int, int>, int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |   if(mp.size()==n*(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... |