Language: C++

#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

ll visit[2345678];
signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	
	ll n, m, a, b; cin >> n >> m;
	vector<vector<ll>> G(n + 2);
	rep(i, m) {
		cin >> a >> b;
		G[a].push_back(b); G[b].push_back(a);
	}
	vector<ll> start, goal;
	visit[a] = 1; visit[b] = 1;
	ll x = a, y = b;
	while (true) {
		bool ng = false;
		rep(i, G[x].size()) {
			if (visit[G[x][i]] == 0) {
				x = G[x][i];
				visit[x] = 1; start.push_back(x); ng = true; break;
			}
		}
		if (!ng) { break; }
	}
	while (true) {
		bool ng = false;
		rep(i, G[y].size()) {
			if (visit[G[y][i]] == 0) {
				y = G[y][i]; visit[y] = 1; goal.push_back(y); ng = true; break;
			}
		}
		if (!ng) { break; }
	}
	reverse(all(start));

	cout << start.size() + goal.size() + 2 << endl;

	rep(i, start.size()) {
		cout << start[i] << ' ';
	}
	cout << a << ' ' << b;
	rep(i, goal.size()) {
		cout << ' ' << goal[i];
	}
	cout << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:9: error: reference to 'visit' is ambiguous
   27 |         visit[a] = 1; visit[b] = 1;
      |         ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:15:4: note:                 'll visit [2345678]'
   15 | ll visit[2345678];
      |    ^~~~~
a.cc:27:23: error: reference to 'visit' is ambiguous
   27 |         visit[a] = 1; visit[b] = 1;
      |                       ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:15:4: note:                 'll visit [2345678]'
   15 | ll visit[2345678];
      |    ^~~~~
a.cc:32:29: error: reference to 'visit' is ambiguous
   32 |                         if (visit[G[x][i]] == 0) {
      |                             ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:15:4: note:                 'll visit [2345678]'
   15 | ll visit[2345678];
      |    ^~~~~
a.cc:34:33: error: reference to 'visit' is ambiguous
   34 |                                 visit[x] = 1; start.push_back(x); ng = true; break;
      |                                 ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:15:4: note:                 'll visit [2345678]'
   15 | ll visit[2345678];
      |    ^~~~~
a.cc:42:29: error: reference to 'visit' is ambiguous
   42 |                         if (visit[G[y][i]] == 0) {
      |                             ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:15:4: note:                 'll visit [2345678]'
   15 | ll visit[2345678];
      |    ^~~~~
a.cc:43:46: error: reference to 'visit' is ambiguous
   43 |                                 y = G[y][i]; visit[y] = 1; goal.push_back(y); ng = true; break;
      |                                              ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:15:4: note:                 'll visit [2345678]'
   15 | ll visit[2345678];
      |    ^~~~~