#include <bits/stdc++.h>
using namespace std;
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
vector<vector<pair<int, int>>> adj(N);
for (int i = 0; i < M; ++i) {
if (i % 2 == 0) {
adj[U[i]].push_back({V[i], i}), adj[V[i]].push_back({U[i], i});
}
}
vector<int> vis_edge(M);
int good = 0;
vector<int> ans;
auto dfs = [&](auto &&self, int u) {
vector<int> chs;
for (auto &[i, idx] : adj[u]) {
if (vis_edge[idx]) {
continue;
}
chs.push_back(idx);
}
if (chs.empty()) {
return;
}
if (chs.size() == 1) {
vis_edge[chs[0]] = true;
ans.push_back(chs[0]);
self(self, U[chs[0]] + V[chs[0]] - u);
ans.push_back(chs[0]);
return;
}
good = 1;
ans.push_back(chs[0]);
ans.push_back(chs[0] + 1);
ans.push_back(chs[1]);
ans.push_back(chs[1] + 1);
ans.push_back(chs[0] + 1);
ans.push_back(chs[0]);
ans.push_back(chs[1] + 1);
ans.push_back(chs[1]);
};
dfs(dfs, 0);
if (!good) {
return false;
}
return ans;
}
#ifdef MACOS_LOCAL
#include "grader.cpp"
#endif