Problem:
分割統治
太郎さんと花子さんと次郎さんは3人で JAG 王国を統治している．JAG 王国には
N
個の街が存在し，いくつかの街は双方向の道路で繋がっている．どの街からも別のすべての街へ 1 本以上の道路を経由して必ず辿り着くことができる．
ある日太郎さんと花子さんはとうとう仲違いを起こしてしまい，3 人で街を分担して統治することに決めた．しかし，あまりにも仲が悪くなりすぎてしまったため，太郎さんが統治している街と花子さんが統治している街が 1 本の道路で直接繋がっていることすら嫌がっている．そこで，以下の条件を満たすように統治する街を分担することにした．
太郎さんが統治する街と花子さんが統治する街からなる任意のペアは，直接道路で繋がっていない．これは太郎さんと花子さんの仲がめちゃくちゃ悪いからである．
同じ人に統治されている街同士も直接道路で繋がっていない．これは，そんな中でも他者の統治下の経由を義務付けることで外交を促すためである．
太郎さんの統治する街の総数と花子さんが統治する街の総数は同じでなければならない．これは総数を等しくしないと太郎さんと花子さんの仲がさらにめちゃくちゃ悪くなりそうだからである．ここで，次郎さんはとても心が広いので，次郎さんが統治する街の総数はいくつでもよい．
以上の条件を満たすような分担であれば，3 人は納得して統治することができ，たとえ誰かの統治する街が 0 個であっても文句はない．このとき，太郎さんが統治する街の総数 (=花子さんが統治する街の総数) としてあり得る数をすべて列挙するプログラムを作成せよ．
Input
入力は複数のデータセットからなる．
データセットの数は最大で 50 である．
各データセットは，次の形式で表される．
N
M
u
1
v
1
...
u
M
v
M
1 行目は 2 つの整数
N
(
2 ≤ N ≤ 10
3
) と
M
(
1 ≤ M ≤ 10
3
) からなり，それぞれ街の数と道路の数を表す．続く
M
行のうち
i
行目は 2 つの整数
u
i
と
v
i
(
1 ≤ u
i
< v
i
≤ N
) からなり，
i
番目の道路が街
u
i
と 街
v
i
を双方向に繋いでいることを表す．ここで，どの街からも別のすべての街へ 1 本以上の道路を経由して必ず辿り着くことができることが保証される．また，同じ街のペアを結ぶ道路が複数与えられることはない．すなわち，すべての
1 ≤ i < j ≤ M
について
(u
i
, v
i
) ≠ (u
j
, v
j
)
を満たす．
入力の終わりは 2 つのゼロからなる行で表される．
Output
各データセットについて，太郎さんが統治する街の総数として考えられる数が
K
通りあるとき，まず 1 行目に
K
を出力し，その後，あり得る総数を 1 行に 1 つずつ昇順で出力せよ．
Sample Input
6 7
1 2
1 4
2 3
2 5
3 4
4 5
4 6
2 1
1 2
3 3
1 2
1 3
2 3
4 3
1 2
2 3
3 4
5 4
1 2
2 3
3 4
4 5
0 0
Output for the Sample Input
2
1
2
0
0
1
1
1
1

Submitted solutions:

code_snippet: //#define _GLIBCXX_DEBUG

#include <iostream>
#include <vector>
#include <queue>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <iterator>
#include <unordered_map>
#include <stack>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <unordered_set>

using namespace std;
using ll = long long;

const ll MOD = 998244353;
const ll MOD2 = 1'000'000'007;

class SegTree {
public:
    vector<ll> dat;
    ll siz = 1;

    SegTree(ll n) {
        while (siz < n) siz *= 2;
        dat.resize(2 * siz, -LLONG_MAX);
    }

    void update(int id, ll x) {
        id += siz;
        dat[id] = x;
        while (id != 0) {
            id /= 2;
            dat[id] = max(dat[2 * id], dat[2 * id + 1]);
        }
    }

    ll getval(int id) {
        return dat[id + siz];
    }

    ll getmax(ll L, ll R, ll a, ll b, ll u) {
        if (b <= L || R <= a) return -LLONG_MAX / 2;
        if (L <= a && b <= R) return dat[u];
        ll m = (a + b) / 2;
        return max(getmax(L, R, a, m, 2 * u),
            getmax(L, R, m, b, 2 * u + 1));
    }
};

class UnionFind {
public:
    vector<int> siz, par;
    UnionFind(int n) {
        siz.assign(n, 1);
        par.assign(n, -1);
    }
    int root(int x) {
        return par[x] == -1 ? x : par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x), ry = root(y);
        if (rx == ry) return;
        if (siz[rx] < siz[ry]) {
            par[rx] = ry;
            siz[ry] += siz[rx];
        }
        else {
            par[ry] = rx;
            siz[rx] += siz[ry];
        }
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; if (u < 0) u += m;
    return u;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int dx[] = { 1, 0, -1, 0 }, dy[] = { 0, 1, 0, -1 };

//ios::sync_with_stdio(false);
//cin.tie(nullptr);



int N, M;

int check(vector<vector<int>>& G, vector<int>& cnt) {
    queue<int> q;
    q.push(1);//頂点１を黒で塗る
    vector<int> cols(N + 1, 0);
    cols[1] = 1;

    while (!q.empty()) {
        int pos = q.front(); q.pop();

        for (int i = 0; i < G[pos].size(); i++) {
            int nex = G[pos][i];
            if (cols[pos] == cols[nex] && cols[pos] != 0)return -1;//もう訪問済みで色が被った場合
            if (cols[nex] != 0)continue;//訪問済みで別の色

            if (cols[pos] == 1) {
                cols[nex] = -1;
                q.push(nex);
            }
            else {
                cols[nex] = 1;
                q.push(nex);
            }

        }
    }
    int k = 0;

    for (int i = 1; i <= N; i++) {
        if (cols[i] == 1)k++;
    }

    
    if (k % 2 == 0)cnt.push_back(k / 2);
    if ((N - k) % 2 == 0 && N - k != k)cnt.push_back((N - k) / 2);

    return cnt.size();
}


int main() {
   
    while (true) {
        
        cin >> N >> M;

        if (N == 0 && M == 0)return 0;

        vector<vector<int>> G(N + 1);
        for (int i = 0; i < M; i++) {
            int u, v; cin >> u >> v;
            G[u].push_back(v);
            G[v].push_back(u);
        }

        vector<int> cnt;
        int ans = check(G, cnt);

        if (ans == -1) {
            cout << 0 << endl;
            continue;
        }

        cout<<ans<<endl;
        sort(cnt.begin(),cnt.end());

        for (int i = 0; i < ans; i++) {
            cout << cnt[i] << endl;
        }

        
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3240
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define int long long

vector<int> dist;
vector<int> odd, even;
vector<bool> seen;//falesで埋める
void dfs (vector<vector<int>> &g, int v, int d=0) {
    seen[v] = true;
    dist[v] = d%2;
    if (d%2 == 0) even.push_back(v);
    else odd.push_back(v);
    for (auto nv : g[v]) {
        if (seen[nv] == true) continue;
        dfs(g, nv, d+1);
    }
}

void solve(int n, int m) {
    vector<vector<int>> g(n);
    set<pair<int, int>> edges;
    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);
        if (u > v) swap(u, v);
        edges.insert({u, v});
    }

    dist.assign(n, -1);
    seen.assign(n, false);
    odd.clear();
    even.clear();
    dfs(g, 0);

    sort(odd.begin(), odd.end());
    odd.erase(unique(odd.begin(), odd.end()), odd.end());
    sort(even.begin(), even.end());
    even.erase(unique(even.begin(), even.end()), even.end());

    // for (auto x: dist) cout << x << ' ';
    // cout << endl;
    // cout << "odd" << endl;
    // for (auto x: odd) cout << x << ' ';
    // cout << endl;
    // cout << "even" << endl;
    // for (auto x: even) cout << x << ' ';
    // cout << endl;

    bool ok = true;
    for (int i=0; i<odd.size(); ++i) {
        for (int j=i+1; j<odd.size(); ++j) {
            if (edges.count({odd[i], odd[j]})) {
                ok = false;
            }
        }
    }
    for (int i=0; i<even.size(); ++i) {
        for (int j=i+1; j<even.size(); ++j) {
            if (edges.count({even[i], even[j]})) {
                ok = false;
            }
        }
    }
    if (!ok) {
        cout << 0 << endl;
        return;
    }


    vector<int> ans;
    //oddを次郎にする
    if (even.size() > 0 && even.size() % 2 == 0) {
        ans.push_back(even.size() / 2);
    }
    //evenを次郎にする
    if (odd.size() > 0 && odd.size() % 2 == 0) {
        ans.push_back(odd.size() / 2);
    }

    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());

    cout << ans.size() << endl;
    for (auto x: ans) {
        cout << x << endl;
    }
}

signed main() {
    while(true) {
        int n, m;
        cin >> n >> m;
        if (n+m == 0) break;
        solve(n, m);
    }
}

/*
memo

6 7
1 2
1 4
2 3
2 5
3 4
4 5
4 6

2 1
1 2

3 3
1 2
1 3
2 3

4 3
1 2
2 3
3 4

5 4
1 2
2 3
3 4
4 5

0 0


0 0 n
1 1 n-2
2 2 n-4

*/
accuracy: 1
time_ms: 60
memory_kb: 3840
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define ll long long

vector<ll> bfs(vector<vector<ll>> &graph){
    ll n=graph.size();
    vector<ll> ans(n,2000000);
    ll state;
    deque<ll> qu;
    qu.push_back(0);
    ans[0]=0;
    while(qu.size()){
        state=qu.front();
        qu.pop_front();
        for(ll i=0;i<(ll)graph[state].size();i++){
            if(ans[graph[state][i]]!=2000000){
                if((ans[graph[state][i]]+ans[state])%2==0){
                    return {-1};
                }
                else if(ans[graph[state][i]]>ans[state]+1){
                    ans[graph[state][i]]=ans[state]+1;
                    qu.push_back(graph[state][i]);
                }
            }
            else if(ans[graph[state][i]]>ans[state]+1){
                ans[graph[state][i]]=ans[state]+1;
                qu.push_back(graph[state][i]);
            }
        }
    }
    return ans;
}

ll solve(){
    ll n,m,u,v;
    cin>>n>>m;
    if(n==0 && m==0)return 0;
    vector<vector<ll>> graph(n,vector<ll>(0,0));
    for(ll i=0;i<m;i++){
        cin>>u>>v;
        graph[u-1].push_back(v-1);
        graph[v-1].push_back(u-1);
    }
    set<ll> ans;
    vector<ll> distance=bfs(graph);
    if(distance==vector<ll>{-1}){
        cout<<0<<endl;
        return 1;
    }
    ll kisuu=0,gusuu=0;
    for(ll i=0;i<n;i++){
        if(distance.at(i)%2==0) gusuu+=1;
        else kisuu+=1;
    }
    if(kisuu%2==0)ans.insert(kisuu/2);
    if(gusuu%2==0)ans.insert(gusuu/2);
    cout<<ans.size()<<endl;
    for(ll p:ans)cout<<p<<endl;
    return 1;
}

int main(){
	#define ll long long
    while(solve()){}
}
accuracy: 1
time_ms: 10
memory_kb: 3448
final_rank: 4

code_snippet: #define _USE_MATH_DEFINES
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using H = pair<int, int>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
#define all(a) (a).begin(), (a).end()
#define fs first
#define sc second
#define rng(i, s, n) for(int i = (s) ; i < (n) ; i++)
#define rep(i, n) rng(i, 0, (n))
#define mkp make_pair
#define vec vector
#define pb emplace_back
#define siz(a) int((a).size())
#define crdcomp(b) sort(all((b))); (b).erase(unique(all((b))), (b).end())
#define getidx(b, i) (lower_bound(all((b)), (i))-(b).begin())
#define cdf(n) for(int __quetimes=(n); __quetimes>0; __quetimes--)
#define readv(a, n) (a).resize((n), 0); rep(i, (n)) (a)[i]=read()
#define found(a, x) (a.find(x)!=a.end())
#define slp(x, y) make_pair(min((x), (y)), max((x), (y)))
constexpr ll mod = (ll)1e9 + 7;
constexpr ll Mod = 998244353;
constexpr ld EPS = 1e-10;
constexpr ll inf = (ll)3 * 1e18;
constexpr int Inf = 1e9 + 10;
constexpr int dx[] = { -1, 1, 0, 0 }, dy[] = { 0, 0, -1, 1 };
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T = ll>T read() { T u, k = scanf("%lld", &u); return u; }
template<typename T>bool ina(pair<T, T> t, T h, T w) { return 0 <= t.fs && t.fs < h && 0 <= t.sc && t.sc < w; }
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
template<typename T>void fin(T x) { cout << x << endl; exit(0); }
void outv(vector<ll>v) { for (int i = 0;i < v.size();i++) printf("%lld%c", v[i], " \n"[i == int(v.size()) - 1]); }/*
#include<atcoder/all>
using namespace atcoder;//*/
//-------------------------------------------------------------

signed main() {
	int n, m;
	while (cin >> n >> m && n > 0) {
		vec<vec<int>>e(n);
		rep(i, m) {
			int u, v;cin >> u >> v;
			u--;v--;
			e[u].pb(v);
			e[v].pb(u);
		}

		queue<int>q;
		q.push(0);
		vi a(n, -1);
		a[0] = 0;
		bool flag = false;
		while (!q.empty()) {
			int t = q.front();q.pop();
			for (auto g : e[t]) {
				if (a[g] == -1) {
					a[g] = 1 - a[t];
					q.push(g);
				}
				else if (a[g] == a[t]) {
					flag = true;
				}
			}
		}
		if (flag) {
			cout << "0\n";
		}
		else {
			int t = count(all(a), 0);
			set<int>s;
			if (t % 2 == 0) s.insert(t / 2);
			if ((n - t) % 2 == 0) s.insert((n - t) / 2);
			cout << s.size() << endl;
			for (auto g : s) cout << g << endl;
		}
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3452
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;

int main(void) {
    int n, m;
    while(cin >> n >> m) {
        if (n == 0 && m == 0) break;

        vector<vector<int>> g(n);
        rep(i,m) {
            int u, v;
            cin >> u >> v;
            u--; v--;
            g[u].push_back(v);
            g[v].push_back(u);
        }
        vector<int> color(n,-1);
        bool ok = true;
        auto dfs = [&](auto f, int v, int c) -> void {
            color[v] = c;
            for (int next_v: g[v]) {
                if (color[next_v] != -1) {
                    if (color[next_v] == color[v]) {
                        ok = false;
                    }
                    continue;
                }
                f(f,next_v,c^1);
            }
        };
        dfs(dfs, 0, 0);
        if (!ok) {
            cout << 0 << "\n";
            continue;
        }
        
        int count[2] = {0, 0};
        rep(i,n) {
            count[color[i]]++;
        }
        int mx = max(count[0], count[1]);
        int tmp = 2;
        set<int> ans;
        if (count[0] % 2 == 0) ans.insert(count[0]/2);
        if (count[1] % 2 == 0) ans.insert(count[1]/2);
        cout << ans.size() << "\n";
        for (int ans_ele : ans) cout << ans_ele << "\n";
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3480
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(v) v.begin(),v.end()
#define dbg(x) cerr << #x << ": " << (x) << endl;

void solve() {
    int n,m;
    cin >> n >> m;
    if (n+m == 0) exit(0);
    vector<vector<pair<int,int>>> g(n);
    vector<pair<int,int>> e(m);
    for (int i = 0; i < m; ++i) {
        int a,b;
        cin >> a >> b;
        --a; --b;
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
        e[i].first = a;
        e[i].second = b;
    }

    queue<int> q;
    int inf = 1e9;
    vector<int> dis(n, inf);
    dis[0] = 0;
    q.push(0);
    while (q.size()) {
        int pos = q.front();
        q.pop();
        for (auto [to,eid] : g[pos]) {
            if (dis[to] > dis[pos] + 1) {
                dis[to] = dis[pos] + 1;
                q.push(to);
            }
        }
    }
    // for (int i = 0; i < n; ++i) cerr << dis[i] << " \n"[i==n-1];

    bool ok = true;
    for (auto [a,b] : e) {
        if (dis[a] == dis[b]) {
            ok = false;
            break;
        }
    }
    if (ok) {
        int cnt = 0;
        for (int i = 0; i < n; ++i) if (dis[i] % 2) ++cnt;
        vector<int> ans;
        if (n % 2 == 0) {
            if (cnt % 2 == 0) {
                ans.push_back(cnt / 2);
                ans.push_back((n - cnt) / 2);
            }
        }
        else {
            if (cnt % 2 == 0) {
                ans.push_back(cnt / 2);
            }
            else {
                ans.push_back((n - cnt) / 2);
            }
        }
        sort(ALL(ans));
        ans.erase(unique(ALL(ans)), ans.end());
        cout << ans.size() << '\n';
        for (int i : ans) {
            cout << i << '\n';
        }
    }
    else {
        cout << "0\n";
    }
}

int main() {
    while (true) solve();
}
accuracy: 1
time_ms: 10
memory_kb: 3288
final_rank: 2

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

int main() {
while(1) {
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0) return 0;
    vector<vector<int>> G(N);
    vector<int> U(M), V(M);
    rep(i,0,M) {
        cin >> U[i] >> V[i];
        U[i]--, V[i]--;
        G[U[i]].push_back(V[i]);
        G[V[i]].push_back(U[i]);
    }
    vector<int> D(N,-1);
    D[0] = 0;
    queue<int> Q;
    Q.push(0);
    while(!Q.empty()) {
        int P = Q.front();
        Q.pop();
        for (int NP : G[P]) {
            if (D[NP] == -1) {
                D[NP] = 1 - D[P];
                Q.push(NP);
            }
        }
    }
    bool check = true;
    rep(i,0,M) {
        if (D[U[i]] == D[V[i]]) check = false;
    }
    if (!check) {
        cout << 0 << endl;
        continue;
    }
    int COUNT = 0;
    rep(i,0,N) COUNT += D[i];
    vector<int> ANS;
    if (COUNT % 2 == 0) ANS.push_back(COUNT / 2);
    if ((N - COUNT) % 2 == 0) ANS.push_back((N - COUNT) / 2);
    UNIQUE(ANS);
    cout << ANS.size() << endl;
    rep(i,0,ANS.size()) cout << ANS[i] << endl;
}
}
accuracy: 1
time_ms: 10
memory_kb: 3600
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

#define rep(i,a,n) for(ll i = a; i < n; i++)

int main(){
    
    while(true){
        ll n,m;
        cin >> n >> m;

        if(n == 0) break;

        auto solve = [&](){
            vvll G(n);
            rep(i,0,m){
                ll u,v;
                cin >> u >> v;
                u--; v--;
                G[u].emplace_back(v);
                G[v].emplace_back(u);
            }

            vll cnt(2);
            vll color(n,-1);
            queue<ll> que;
            que.emplace(0);
            color[0] = 0;
            cnt[0] = 1;
            while(!que.empty()){
                ll v = que.front();
                que.pop();

                for(auto nv : G[v]){
                    if(color[nv] == -1){
                        color[nv] = 1 - color[v];
                        cnt[color[nv]]++;
                        que.emplace(nv);
                    }
                    else if(color[nv] != 1 - color[v]){
                        cout << 0 << endl;
                        return;
                    }
                }
            }

            set<ll> st;
            if(cnt[0] % 2 == 0) st.insert(cnt[0]/2);
            if(cnt[1] % 2 == 0) st.insert(cnt[1]/2);

            cout << st.size() << endl;
            for(auto val : st) cout << val << endl;
        };
        solve();
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3556
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using ll = long long;
#define all(p) p.begin(),p.end()

void solve(int N, int M){
    vector<vector<int>> G(N);
    rep(i, 0, M){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> col(N, -1);
    col[0] = 0;
    vector<int> order = {0};
    int S = 0;
    bool ok = 1;
    rep(i, 0, N){
        int a = order[i];
        for (auto x : G[a]){
            if (col[x] == -1){
                col[x] = (col[a] ^ 1);
                S += col[x];
                order.push_back(x);
            }
            else if (col[x] == col[a]){
                ok = 0;
            }
        }
    }
    set<int> s;
    if (S % 2 == 0) s.insert(S);
    if ((N - S) % 2 == 0) s.insert(N - S);
    if (!ok) s.clear();
    cout << s.size() << "\n";
    for (auto x : s) cout << x / 2 << "\n";
}

int main(){
    int N, M;
    while (cin >> N >> M, N) solve(N, M);
}
accuracy: 1
time_ms: 10
memory_kb: 3544
final_rank: 13

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;

using ll = long long;
using i64 = long long;
using pll = pair<ll,ll>;
using plll = pair<pll,ll>;

constexpr ll mod = 998244353;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using Graph =vector<vector<ll>>;


bool is_Bipartite(int v, Graph& G, vector<int>& F){
    bool ret=true;
    for (auto nv: G[v]){
        if (F[nv]==F[v])return false;
        if (F[nv]==-1){
            F[nv]=1-F[v];
            ret=ret & is_Bipartite(nv,G,F);
        }
    }
    return ret;

}

int main(){
    while (true){
        int n,m;
        cin>>n>>m;
        if (n==0) break;
        Graph G(n);
        for (int i=0; i<m; i++){
            int a,b;
            cin>>a>>b;
            a--;
            b--;
            G[a].push_back(b);
            G[b].push_back(a);
        }
        vector<int> F(n,-1);
        F[0]=0;

        set<int> se;
        if (is_Bipartite(0,G,F)){


            int white=0;
            for (int v=0; v<n; v++){
                white+=F[v];
            }
            if (white%2==0)se.insert(white/2);
            if ((n-white)%2==0)se.insert((n-white)/2);


        }
        cout<<se.size()<<endl;
        for (auto v: se)cout<<v<<endl;





    }





}
accuracy: 1
time_ms: 10
memory_kb: 3520
final_rank: 11

code_snippet: #include <bits/stdc++.h>

int solve() {
    int n, m;
    std::cin >> n >> m;
    if (n == 0) return 1;
    std::vector graph(n, std::vector<int>());
    for (int i = 0; i < m; i++) {
        int u, v;
        std::cin >> u >> v;
        u--; v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    std::vector<int> color(n, -1);
    int one = 0;
    auto dfs = [&](auto self, int u) -> bool {
        assert(color[u] != -1);
        one += color[u];
        for (auto v: graph[u]) {
            if (color[v] == -1) {
                color[v] = color[u] ^ 1;
                if (!self(self, v)) return false;
            } else if (color[u] == color[v]) {
                return false;
            }
        }
        return true;
    };
    color[0] = 0;
    if (!dfs(dfs, 0)) {
        std::cout << 0 << '\n';
        return 0;
    }
    int zero = n - one;
    std::set<int> ans;
    if (one % 2 == 0) ans.insert(one / 2);
    if (zero % 2 == 0) ans.insert(zero / 2);
    std::cout << ans.size() << '\n';
    for (auto v: ans) std::cout << v << '\n';
    return 0;
}

int main() {
    while (!solve());
}
accuracy: 1
time_ms: 10
memory_kb: 3320
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define loop(i,m,n) for(long long i=m;i<=n;i++)
bool is_b = true;
bool is_bipartite(vector<vector<ll>> &G, vector<ll> &color, ll col, ll v) {
    color[v] = col;

    for (auto nv : G[v]) {
        if (color[nv] == -1) is_bipartite(G, color, abs(col - 1), nv);
        else if (color[nv] == col) {is_b = false; return false;}
    }

    return true;
}

void solve() {
    while (1) {
    is_b = true;
    ll n,m;
    cin >> n >> m;
    if (!n) break;
    vector<vector<ll>> G(n);
    set<ll> ans;
    for (ll i = 0; i < m; ++i) {
        ll u,v;
        cin >> u >> v;
        --u,--v;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    rep(i,n) {
        vector<ll> color(n,-1);
        is_bipartite(G,color,0,i);
        if (is_b) {

            ll cnt = accumulate(color.begin(), color.end(),0ll);
            if (cnt %2 == 0) {
                ans.insert(cnt/2);
            }
        }
    }

    cout << ans.size() << endl;
    for (auto a : ans) {
        cout << a << endl;
    }
    }
}

int main() {
    solve();
    return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 3432
final_rank: 19

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define popcount(x) __builtin_popcountll(x)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<long long,long long>;
const int inf = 1e9+10;
const long long INF = 4e18;
//const int MOD = 1000000007;
const int MOD = 998244353;
const double PI = 3.14159265358979323846;
template<class T, class K>bool chmax(T &a, const K b) { if (a<b) { a=b; return true; } return false; }
template<class T, class K>bool chmin(T &a, const K b) { if (b<a) { a=b; return true; } return false; }
#ifdef LOCAL_
#define debug(var)  do{std::cerr << "\033[1;36m" << #var << ": \033[0m";view(var);std::cerr << std::endl;}while(0)
template<typename T> void view(T e){std::cerr << e;}
template<typename T, typename K> void view(pair<T, K> e){std::cerr << "("; view(e.first); std::cerr << ", "; view(e.second); std::cerr << ")";}
template<typename T> void view(const set<T> &st){ std::cerr << "\n";for(const auto& e : st){view(e); std::cerr << " ";}}
template<typename T, typename K> void view(const map<T, K> &mp){ std::cerr << "\n";for(const auto& [k, v]: mp){std::cerr << "("; view(k); std::cerr << ", "; view(v); std::cerr << ") ";}}
template<typename T, typename K> void view(const unordered_map<T, K> &mp){ std::cerr << "\n";for(const auto& [k, v]: mp){std::cerr << "("; view(k); std::cerr << ", "; view(v); std::cerr << ") ";}}
template<typename T> void view(const std::vector<T>& v){std::cerr << "\n";for(const auto& e : v){ view(e); std::cerr << " "; }}
template<typename T> void view(const std::vector<std::vector<T>>& vv){std::cerr << "\n";int cnt = 0;for(const auto& v : vv){cerr << cnt << "th : "; view(v); cnt++; std::cerr << std::endl;}}
#else
#define debug(...) (void(0))
#endif


template<int mod> struct ModInt{
    long long x=0; 
    constexpr ModInt(long long x=0):x((x%mod+mod)%mod){}
    constexpr ModInt operator+(const ModInt& r)const{return ModInt(*this)+=r;}
    constexpr ModInt operator-(const ModInt& r)const{return ModInt(*this)-=r;}
    constexpr ModInt operator*(const ModInt& r)const{return ModInt(*this)*=r;}
    constexpr ModInt operator/(const ModInt& r)const{return ModInt(*this)/=r;}
    constexpr ModInt& operator+=(const ModInt& r){ if((x+=r.x)>=mod) x-=mod; return *this;}
    constexpr ModInt& operator-=(const ModInt& r){ if((x-=r.x)<0) x+=mod; return *this;}
    constexpr ModInt& operator*=(const ModInt& r){ if((x*=r.x)>=mod) x%=mod; return *this;}
    constexpr ModInt& operator/=(const ModInt& r){ return *this*=r.inv();}
    constexpr bool operator==(const ModInt& r){ return x == r.x;}
    constexpr bool operator!=(const ModInt& r){ return x != r.x;}
    ModInt inv() const {
        long long s=x,sx=1,sy=0,t=mod,tx=0,ty=1;
        while(s%t!=0){
            long long temp=s/t,u=s-t*temp,ux=sx-temp*tx,uy=sy-temp*ty;
            s=t;sx=tx;sy=ty;
            t=u;tx=ux;ty=uy;
        }
        return ModInt(tx);
    }
    ModInt pow(long long n) const {
        ModInt a=1;
        ModInt b=*this;
        while(n>0){
            if(n&1) a*=b;
            b*=b;
            n>>=1;
        }
        return a;
    }
    friend constexpr ostream& operator<<(ostream& os,const ModInt<mod>& a) {return os << a.x;}
    friend constexpr istream& operator>>(istream& is,ModInt<mod>& a) {return is >> a.x;}
};
using mint = ModInt<MOD>;

void dfs(vector<vector<int>> &G, int v, int p, vector<int> &color, int &f){
  
  	//cout << v << " " << p << " " << color[v] << endl;
    int c = color[v] * (-1);
    if(f == 1) return;
    for(auto nv : G[v]){
      	//cout << "nv " << nv << endl;
        if(nv == p) continue;
        if(color[nv] != 0){
          	//cout << color[nv] << " " << color[v] << endl;
            if(color[nv] == color[v]){
                f = 1;
                return;
            }
        }
        else{
            color[nv] = c;
            dfs(G, nv, v, color, f);
        }
    }

    return;
}

int main() {
    
    while(1){    
        int n, m;
        cin >> n >> m;
      	if(n == 0 && m == 0) break;
        vector<vector<int>> G(n);
        rep(i, m){
            int u, v; cin>>u>>v;
            u--; v--;
            G[u].push_back(v);
            G[v].push_back(u);
        }
        vector<int> used(n, 0);
        vector<int> color(n, 0);
        int f = 0;
        color[0] = 1;
        dfs(G, 0, -1, color, f);
        if(f == 1){
            cout << 0 << endl;
            continue;
        }
        int r = 0;
        rep(i, n){
            if(color[i] == 1) r++;
        }
        int b = n - r;
      	//cout << r << " " << b << endl;
        if(r > b) swap(r, b);
        if(r % 2 == 0 && b % 2 == 0){
          	if(r == b){
              cout << 1 << endl;
              cout << r / 2 << endl;
            }
          	else{
              cout << 2 << endl;
              cout << r / 2 << endl;
              cout << b / 2 << endl;
            }
        }
        else if(r % 2 == 0){
            cout << 1 << endl;
            cout << r / 2 << endl;
        }
        else if(b % 2 == 0){
            cout << 1 << endl;
            cout << b / 2 << endl;
        }
        else{
            cout << 0 << endl;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3456
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
bool solve() {
  int N, M;
  cin >> N >> M;
  if( N == 0 && M == 0 ) return false;
  vector<vector<int>> G(N, vector<int>());
  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);
  }
  int is_bipartite = true;
  queue<int> que;
  vector<int> color(N, -1);
  color[0] = 0;
  que.push(0);
  while( !que.empty() ) {
    int cur = que.front();
    que.pop();
    for( int nxt : G[cur] ) {
      if( color[nxt] == -1 ) {
        color[nxt] = color[cur]^1;
        que.push(nxt);
      }else if( color[cur] == color[nxt] ) {
        is_bipartite = false;
      }
    }
  }
  if( is_bipartite ) {
    vector<int> cnt(2);
    set<int> ansv;
    for( int i = 0; i < N; i++ ) {
      cnt[color[i]]++;
    }
    if( cnt[0]%2 == 0 ) ansv.insert(cnt[0]/2);
    if( cnt[1]%2 == 0 ) ansv.insert(cnt[1]/2);
    cout << ansv.size() << endl;
    for( int ans : ansv ) {
      cout << ans << endl;
    }
  }else {
    cout << 0 << endl;
  }
  return true;
}
int main() {
  while(solve()){}
}
accuracy: 1
time_ms: 10
memory_kb: 3540
final_rank: 12

code_snippet: #include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int main() {
    while (true) {
        int N, M;
        cin >> N >> M;
        if (N == 0) {
            break;
        }
        vector<int> u(M);
        vector<int> v(M);
        for (int i = 0; i < M; i++) {
            cin >> u[i] >> v[i];
            u[i]--;
            v[i]--;
        }
        vector<vector<int>> graph(N, vector<int>(0));
        for (int i = 0; i < M; i++) {
            graph[u[i]].push_back(v[i]);
            graph[v[i]].push_back(u[i]);
        }
        bool pos = true;
        vector<int> color(N, -1);
        color[0] = 0;
        queue<int> que;
        que.push(0);
        while (que.size()) {
            if (!pos) {
                break;
            }
            int p = que.front();
            que.pop();
            for (int x : graph[p]) {
                if (color[x] != -1) {
                    if (color[x] == color[p]) {
                        pos = false;
                        break;
                    }
                    continue;
                }
                color[x] = 1 - color[p];
                que.push(x);
            }
        }
        if (!pos) {
            cout << 0 << endl;
        } else {
            int red = 0;
            int blue = 0;
            for (int i = 0; i < N; i++) {
                if (color[i] == 0) {
                    red++;
                } else {
                    blue++;
                }
            }
            vector<int> ans(0);
            if (red % 2 == 0) {
                ans.push_back(red / 2);
            }
            if (blue % 2 == 0 && blue != red) {
                ans.push_back(blue / 2);
            }
            if (ans.size() == 0) {
                cout << 0 << endl;
            } else {
                sort(ans.begin(), ans.end());
                cout << ans.size() << endl;
                for (int i = 0; i < ans.size(); i++) {
                    cout << ans[i] << endl;
                }
            }
        }
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3452
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

bool dfs(int v, int cl, vector<vector<int>> &g, vector<int> &colors){
    colors[v] = cl;
    bool flag = true;
    for (auto nxt : g[v]){
        if (colors[nxt] == cl) return false;
        if (colors[nxt] == -1){
            flag = min(flag, dfs(nxt, cl ^ 1, g, colors));
        }
    }
    return flag;
}

void solve(int &N, int &M){
    vector<vector<int>> g(N);
    rep(i, M){
        int u, v; cin >> u >> v; u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int> seen(N, -1);
    bool flag = dfs(0, 0, g, seen);
    if (!flag){
        cout << 0 << endl;
        return;
    }
    else{
        int cnta = 0, cntb;
        rep(i, N) if (seen[i] == 0) cnta++;
        cntb = N - cnta;
        if (cnta > cntb) swap(cnta, cntb);
        
        if (cntb % 2 == 0 && cnta % 2 == 0 && cnta != cntb){
            cout << 2 << endl << cnta / 2 << endl << cntb / 2 << endl;
            return;
        }
        else if (cntb % 2 == 1 && cnta % 2 == 1){
            cout << 0 << endl;
            return;
        }
        else{
            cout << 1 << endl;
            if (cntb % 2 == 0) cout << cntb / 2 << endl;
            else if (cnta % 2 == 0) cout << cnta / 2 << endl;
            return;
        }
    }
}

int main(){
    while (true){
        int N, M; cin >> N >> M;
        if (N == 0) return 0;
        solve(N, M);
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3544
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;

bool solve() {
        int N, M; cin >> N >> M;
        if (N == 0) return false;
        vector<vector<int>> G(N);
        for (int _ = 0 ; _ < M ; _++) {
                int u, v; cin >> u >> v;
                u--; v--;
                G[u].push_back(v);
                G[v].push_back(u);
        }

        vector<int> col(N, -1);
        
        auto dfs = [&](auto dfs, int v, int c) -> bool {
               col[v] = c; 
               for (auto x : G[v]) {
                     if (col[x] == c) return false;
                     if (col[x] == 1 - c) continue;
                     if (not dfs(dfs, x, 1 - c)) return false;
               }
               return true;
        };

        bool bip = true;
        for (int i = 0 ; i < N ; i++) {
                if (col[i] == -1) {
                        bip &= dfs(dfs, i, 0);
                }
        }
        if (bip) {
                assert(find(col.begin(), col.end(), -1) == col.end());
                int cnt0 = count(col.begin(), col.end(), 0);
                int cnt1 = N - cnt0;
                vector<int> ans;
                if (cnt0 % 2 == 0) {
                        ans.push_back(cnt0 / 2);
                }
                if (cnt1 % 2 == 0) {
                        ans.push_back(cnt1 / 2);
                }
                sort(ans.begin(), ans.end());
                ans.erase(unique(ans.begin(), ans.end()), ans.end());
                cout << ans.size() << endl;
                for (auto a : ans) cout << a << endl;
        }
        else {
                cout << 0 << endl;
        }

        return true;
}

int main() {
        while (solve()) ;
}
accuracy: 1
time_ms: 10
memory_kb: 3472
final_rank: 8

code_snippet: #include "bits/stdc++.h"

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;

void outvi(vi &a) {
    for (int i = 0; i < a.size(); i++) {
        cout << a[i] << " \n"[i + 1 == a.size()];
    }
}

bool solve(){
    int n;
    int m;
    cin >> n >> m;
    if(n == 0){
        return false;
    }

    vector<int> u(m), v(m);
    vector<vector<int>> edges(n);
    for(int i = 0; i < m; ++i){
        cin >> u[i] >> v[i];
        --u[i], --v[i];
        edges[u[i]].emplace_back(v[i]);
        edges[v[i]].emplace_back(u[i]);
    }
    vector<int> col(n, -1);
    int cnt = 0;
    bool ok = true;
    function<void(int,int,int)> f = [&](int x, int c, int par){
        for(auto y : edges[x]){
            if(y == par){
                continue;
            }
            if(col[y] != -1 && col[y] != (c ^ 1)){
                ok = false;
                return;
            }
            if(col[y] == -1){
                col[y] = c ^ 1;
                f(y, c ^ 1, x);
            }
        }
    };
    for(int i = 0; i < n; ++i){
        if(col[i] == -1){
            col[i] = cnt;
            f(i, cnt, -1);
            cnt += 2;
        }
    }
    if(!ok){
        cout << 0 << endl;
        return true;
    }
    vector<int> cn(cnt, 0);
    for(int i = 0; i < n; ++i){
        cn[col[i]]++;
    }
    int k = cnt / 2;
    vector<vector<int>> dp(k + 1, vector<int>(n + 1, 0));
    dp[0][0] = true;
    for(int i = 0; i < k; ++i){
        for(int j = 0; j <= n; ++j){
            int pat1 = cn[i * 2];
            int pat2 = cn[i * 2 + 1];
            if(!dp[i][j]){
                continue;
            }
            if(j + pat1 <= n)
            dp[i + 1][j + pat1] = true;
            if(j + pat2 <= n)
            dp[i + 1][j + pat2] = true;
        }
    }
    set<int> s;
    for(int i = 0; i < n; i += 2){
        if(dp.back()[i]){
            s.emplace(i / 2);
        }
    }
    cout << s.size() << endl;
    for(auto x : s){
        cout << x << endl;
    }
    return true;
}

int main(){
    while (solve());
}
accuracy: 1
time_ms: 10
memory_kb: 3504
final_rank: 10

code_snippet: #include <bits/stdc++.h>

#define rep(i,s,n) for(int i = int(s); i < int(n); i++)
#define rrep(i,s,n) for(int i = int(n) - 1; i >= (int)s; i--)
#define all(v) v.begin(),v.end()

using ll = long long;
using ull = unsigned long long;
using ld = long double;

template<class T>
bool chmin(T &a, T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

template<class T>
bool chmax(T & a, T b) {
    if(a >= b) return false;
    a = b;
    return true;
}

using namespace std;

int main() {
    while (true){
        int n, m; cin >> n >> m;
        if (n == 0) break;
        vector<vector<int>> es(n);
        rep(i,0,m){
            int u, v; cin >> u >> v; u--, v--;
            es[u].emplace_back(v);
            es[v].emplace_back(u);
        }
        vector<int> a(n,-1);
        queue<int> que;
        a[0] = 0;
        que.push(0);
        bool ng = false;
        while (!que.empty()){
            int p = que.front(); que.pop();
            for (int q : es[p]){
                if (a[q] == -1){
                    a[q] = a[p]^1;
                    que.push(q);
                }
                else if (a[q] == a[p]){
                    ng = true;
                }
            }
        }
        if (ng){
            cout << 0 << endl;
            continue;
        }
        int c0 = 0, c1 = 0;
        rep(i,0,n) (a[i] == 0 ? c0 : c1)++;
        vector<int> ans;
        if (c0 % 2 == 0) ans.emplace_back(c0/2);
        if (c1 % 2 == 0) ans.emplace_back(c1/2);
        sort(all(ans)); ans.erase(unique(all(ans)),ans.end());
        cout << ans.size() << endl;
        rep(i,0,ans.size()) cout << ans[i] << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3548
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define reps(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define rrep(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (ll)n; i > 0; i--)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
#define all(x) x.begin(), x.end()

template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

ll factorial(ll n)
{
    if (n == 1 || n == 0)
        return 1;
    else
        return n * factorial(n - 1);
}

ll combination(ll a, ll b)
{
    return factorial(a) / (factorial(a - b) * factorial(b));
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

vector<ll> divisors(ll n, bool sorted = false)
{
    vector<ll> res;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            res.push_back(i);
            if (i * i != n)
                res.push_back(n / i);
        }
    }
    if (sorted)
    {
        SORT(res);
    }

    return res;
}

vector<bool> eratosthenes(ll n)
{
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = is_prime[1] = false;

    for (ll p = 2; p <= n; p++)
    {
        if (!is_prime[p])
            continue;
        for (int q = p * 2; q <= n; q += p)
        {
            is_prime[q] = false;
        }
    }

    return is_prime;
}

struct Edge
{
    ll to;
    ll weight;
    Edge(ll to, ll weight) : to(to), weight(weight) {}
};
typedef vector<vector<ll>> Graph;
typedef vector<vector<Edge>> WeightedGraph;

vector<ll> dijkstra(const WeightedGraph &g, ll s)
{
    vector<ll> dis(g.size(), LONG_LONG_MAX);
    dis[s] = 0;
    priority_queue<P, vector<P>, greater<P>> pq;

    pq.push({0, s});
    while (!pq.empty())
    {
        auto [current_dis, v] = pq.top();
        pq.pop();
        if (dis[v] < current_dis)
            continue;
        for (auto e : g[v])
        {
            if (chmin(dis[e.to], current_dis + e.weight))
            {
                pq.push({dis[e.to], e.to});
            }
        }
    }
    return dis;
}

vector<ll> topo_sort(const Graph &g)
{
    vector<ll> res;
    ll n = g.size();
    vector<ll> in_deg(n);

    rep(i, n) for (auto vv : g[i]) in_deg[vv]++;

    queue<ll> que;
    rep(i, n) if (in_deg[i] == 0) que.push(i);

    while (!que.empty())
    {
        ll v = que.front();
        res.push_back(v);
        que.pop();
        for (auto vv : g[v])
        {
            in_deg[vv]--;
            if (in_deg[vv] == 0)
                que.push(vv);
        }
    }

    return res;
}

bool dfs(const Graph &g, ll v, vector<int> &color_list, int color)
{
    color_list[v] = color;
    for (auto vv : g[v])
    {
        if (color_list[vv] != -1)
        {
            if (color_list[vv] == color)
                return false;
            continue;
        }
        if (!dfs(g, vv, color_list, 1 - color))
            return false;
    }
    return true;
}

int main()
{
    while (true)
    {
        ll n, m;
        cin >> n >> m;
        if (n == 0 && m == 0)
            break;

        Graph g(n);
        rep(i, m)
        {
            ll a, b;
            cin >> a >> b;
            a--;
            b--;
            g[a].push_back(b);
            g[b].push_back(a);
        }
        vector<int> color_list(n, -1);
        bool is_bipartite = dfs(g, 0, color_list, 0);
        if (!is_bipartite)
        {
            cout << 0 << endl;
            continue;
        }
        vector<ll> cnt(2);
        rep(i, n)
        {
            cnt[color_list[i]]++;
        }

        set<ll> ans;
        if (cnt[0] % 2 == 0)
            ans.insert(cnt[0] / 2);
        if (cnt[1] % 2 == 0)
            ans.insert(cnt[1] / 2);

        cout << ans.size() << endl;
        for (auto x : ans)
            cout << x << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3548
final_rank: 15