#include using namespace std; struct GeneralMatching { struct E { int a, b; }; const vector>& g; int n, sz; vector p, t, mt; vector f; int non(int v) { return t[v] != sz or p[v] == -1 ? v : (p[v] = non(p[v])); } void R(int a, int b) { int d = mt[a]; mt[a] = b; if (d == -1 or mt[d] != a) return; if (f[a].b == -1) { mt[d] = f[a].a; R(f[a].a, d); } else { R(f[a].a, f[a].b); R(f[a].b, f[a].a); } } bool arg(int rt) { queue q; t[rt] = sz; p[rt] = -1; f[rt] = E{-1, -1}; q.push(rt); while (!q.empty()) { int a = q.front(); q.pop(); for (auto b : g[a]) { if (b == rt) continue; if (mt[b] == -1) { mt[b] = a; R(a, b); return true; } if (t[b] == sz) { int x = non(a), y = non(b); if (x == y) continue; int z = rt; while (x != rt or y != rt) { if (y != rt) swap(x, y); if (f[x].a == a and f[x].b == b) { z = x; break; } f[x] = E{a, b}; x = non(f[mt[x]].a); } for (auto v : {non(a), non(b)}) { while (v != z) { t[v] = sz; p[v] = z; q.push(v); v = non(f[mt[v]].a); } } continue; } if (t[mt[b]] == sz) continue; f[b] = E{-1, -1}; t[mt[b]] = sz; p[mt[b]] = b; f[mt[b]] = E{a, -1}; q.push(mt[b]); } } return false; } GeneralMatching(const vector>& gg) : g(gg), n(g.size()), sz(0), p(n), t(n, -1), mt(n, -1), f(n) { for (int i = 0; i < n; i++) { if (mt[i] == -1) { sz += arg(i); } } } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector> G(N); map, int> ID; for(int i = 1; i <= M; i++) { int u, v; cin >> u >> v; u--, v--; G[u].emplace_back(v); G[v].emplace_back(u); ID[minmax(u, v)] = i; } GeneralMatching GM(G); cout << GM.sz << '\n'; for (int i = 0; i < N; i++) { if (i < GM.mt[i]) { cout << ID[minmax(i, GM.mt[i])] << '\n'; // cout << i << ' ' << GM.mt[i] << '\n'; } } } /* https://judge.yosupo.jp/submission/116845 ここからパクりました。本当にごめんなさい... */