#include #define endl '\n' #define TRACE(x) cerr << #x << " = " << x << endl #define SZ(x) ((int)x.size()) #define ALL(x) x.begin(), x.end() #define pb push_back #define L_B lower_bound #define U_B upper_bound //#define LOCAL using namespace std; template inline bool chkmax(T &x, const T1 &y) { return x < y ? x = y, true : false; } template inline bool chkmin(T &x, const T1 &y) { return x > y ? x = y, true : false; } double TL = 4.5; const int MAXN = 100005; int n, m; set g[MAXN]; void read() { cin >> n >> m; if (n != 100000) TL = 4.9; for (int i = 1; i <= n; i++) g[i].clear(); for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; g[u].insert(v); g[v].insert(u); } } vector max_path, curr_path; long long max_cost = 0ll; int timestamp = 0; int used[MAXN]; bool ap[MAXN]; void dfs(int node, int path_idx, long long curr_cost) { used[node] = timestamp; curr_path.pb(node); int exec = 0; for (int nei : g[node]) { if (used[nei] != timestamp) { exec++; dfs(nei, path_idx + 1, curr_cost + nei * path_idx); } } if (!exec && chkmax(max_cost, curr_cost)) max_path = curr_path; curr_path.pop_back(); } int low[MAXN], disc[MAXN]; void init_ap(int node, int parent) { static int timer = 0; used[node] = timestamp; disc[node] = low[node] = ++timer; int children = 0; for (int nei : g[node]) { if (used[nei] == timestamp) chkmin(low[node], disc[nei]); else { children++; init_ap(nei, node); if (parent == -1 && children >= 2) ap[node] = true; else if (parent != -1 && low[nei] >= disc[node]) ap[node] = true; chkmin(low[node], low[nei]); } } } clock_t start; inline bool time_ok() { return ((double)(clock() - start) / (double)CLOCKS_PER_SEC < TL); } void solve() { memset(used, 0, sizeof(used)); memset(ap, false, sizeof(ap)); timestamp++; init_ap(1, -1); max_path.clear(); curr_path.clear(); for (int i = 1; i <= n; i++) { if (!time_ok()) break; if (!ap[i]) { timestamp++; dfs(i, 2, i); } } cout << SZ(max_path) << endl; for (int node : max_path) cout << node << endl; } int main() { start = clock(); #ifndef LOCAL freopen("maxpath.in", "rt", stdin); freopen("maxpath.out", "wt", stdout); #endif // LOCAL ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); read(); solve(); return EXIT_SUCCESS; }