| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1239816 | MarwenElarbi | 수천개의 섬 (IOI22_islands) | C++17 | 0 ms | 0 KiB | 
#include <bits/stdc++.h>
#include "islands.h"
using namespace std;
#define fi first
#define se second
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> adj[1005];
bool vis[1005];
bool test=false;
vector<int> ans;
bool dfs(int x,int p){
    vis[x]=true;
    ans.push_back(x);
    if(adj[x].size()==3){
        int a=-1,b=-1;
        for(auto u : adj[x]){
            if(u==p) continue;
            if(a==-1) a=u;
            else b=u;
        }
        ans.push_back(a);
        ans.push_back(x);
        ans.push_back(b);
        ans.push_back(x);
        ans.push_back(a);
        ans.push_back(x);
        ans.push_back(b);
        ans.push_back(x);
        return true;
    }
    bool test=false;
    for(auto u:adj[x]){
        if(vis[u]) continue;
        if(dfs(u,x)){
            test=true;
            break;
        }
    }
    if(!test) ans.pop_back();
    else ans.push_back(x);
    return test;
}
std::variant<bool, std::vector<int>> find_journey(
    int N, int M, std::vector<int> U, std::vector<int> V) {
    for (int i = 0; i < M; ++i)
    {
        adj[U[i]].push_back(V[i]);
    }
    if(adj[0].size()==2){
        return vector<int>({0,adj[0][0],0,adj[0][1],0,adj[0][0],0,adj[0][1],0});
    }
    if(dfs(0)) return ans;
    return false;
}
