structEdge { int to, next; } e[maxn * 2]; int c1, head[maxn]; inlinevoidadd_edge(int u, int v){ e[c1].to = v; e[c1].next = head[u]; head[u] = c1++; }
int bl[maxn], cnt1, cnt2; stack<int> S; voidprint(){ cout << S.size() << " " << cnt1 << "\n"; while (!S.empty()) { cout << S.top() << " "; S.pop(); } cout << "\n"; vector<int> a1, a2; for (int i = 1; i <= n; ++i) if (bl[i] == -1) a1.push_back(i); elseif (bl[i] == 1) a2.push_back(i); for (auto t : a1) cout << t << " "; cout << "\n"; for (auto t : a2) cout << t << " "; cout << "\n"; exit(0); }
bool vis[maxn]; voiddfs(int u, int fa){ bl[u] = 0; S.push(u); if (--cnt1 == cnt2) print(); vis[u] = 1; for (int i = head[u]; ~i; i = e[i].next) { int v = e[i].to; if (v == fa || vis[v]) continue; dfs(v, u); } bl[u] = -1; S.pop(); if (++cnt2 == cnt1) print(); }
intmain(){ fill(head, head + maxn, -1); ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n >> m; cnt1 = n; cnt2 = 0; for (int i = 1; i <= n; ++i) bl[i] = 1; for (int i = 1; i <= m; ++i) { int x, y; cin >> x >> y; add_edge(x, y); add_edge(y, x); } dfs(1, 0); return0; }