比赛 Asm.Def战记之圣地亚哥“杯2015 评测结果 WAAAWAATTT
题目名称 Asm.Def的游戏 最终得分 50
用户昵称 djj 运行时间 3.024 s
代码语言 C++ 内存使用 22.53 MiB
提交时间 2019-10-23 18:06:36
显示代码纯文本
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>

using namespace std;
const int maxm = 1e6 + 10;
const int maxn = 1e5 + 10;

inline int read() {
    char c = getchar(); int x = 0, f = 1;
    for (; c > '9' || c < '0'; c = getchar()) if (c == '-') f = -1;
    for (; c >='0' && c <='9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
    return x * f;
}

int ver[maxm], nxt[maxm], head[maxn], tot_;
int du[maxn], h[maxn];
bool cut[maxn];
int n, m, ans;

bool cmp (const int &a, const int &b) {
    return du[a] < du[b];
}

void add (int u, int v) {
    ver[++ tot_] = v, nxt[tot_] = head[u], head[u] = tot_;
    ver[++ tot_] = u, nxt[tot_] = head[v], head[v] = tot_;
    ++ du[u], ++ du[v];
}

void djj_lxy () {
    n = read(), m = read();
    for (register int i = 1; i <= n; i ++)
        ans ^= i, h[i] = i;
    for (; m; m --)
        add (read(), read());
    queue <int> q;
    sort (h + 1, h + n + 1, cmp);
    if (du[h[1]] > 2) {
        puts ("0");
        return ;
    }
    for (register int cnt_ = 1; cnt_ <= n; cnt_ ++) {
        if (cut[h[cnt_]]) continue ;
        if (du[h[cnt_]] < 3) q.push (h[cnt_]);
        for (; !q.empty (); ) {
            int u = q.front (); q.pop ();
            cut[u] = 1, ans ^= u;
            for (register int i = head[u]; i; i = nxt[i])
                if (!cut[ver[i]]) {
                    -- du[ver[i]];
                    if (du[ver[i]] < 3)
                        q.push (ver[i]);
                }
        }
        sort (h + cnt_ + 1, h + n + 1, cmp);
        if (du[h[cnt_ + 1]] > 2) break ;
    }
    printf ("%d\n", ans);
}

int main () {
    freopen ("asm_game.in", "r", stdin);
    freopen ("asm_game.out", "w", stdout);
    djj_lxy ();
}

/*
6 10
1 2
1 3
1 4
2 3
2 4
3 4
5 2
5 3
5 6
6 2

4
*/