// Here is a C++17 solution to this problem. typedef vector<int> vi; typedef vector<vi> vvi; int n, m; vvi G; int main(void) { cin >> n >> m; G = vvi(n, vi(0)); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--; v--; G[u].push_back(v); G[v].push_back(u); } bool ok = true; vi dist(n, INT_MAX); for (int u = 0; u < n; u++) { if (dist[u] >= INT_MAX) { queue<int> q; q.push(u); dist[u] = 0; while (!q.empty()) { int v = q.front(); q.pop(); for (auto &w : G[v]) { if (dist[w] >= INT_MAX) { dist[w] = (dist[v] + 1) % 2; q.push(w); } else if (dist[w] == dist[v]) ok = false; } } } } //for (auto &e : dist) cout << e << " "; cout << endl; vvi group(2, vi(0)); if (ok) { for (int u = 0; u < n; u++) group[dist[u]].push_back(u+1); for (auto &g : group) { cout << g.size() << endl; for (auto &e : g) cout << e << " "; cout << endl; } } else cout << -1; return 0; }