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

using namespace std;

const int maxn = 5e5 + 5;

struct Edge {
    int x, y, nxt;
}e[maxn << 1 | 1];

struct Side {
    int fr, to;
}a[maxn];

int n, m, cnt;
int fr, to;

int head[maxn], in[maxn];

bool vis[maxn], chong[maxn];

queue<int> Q;

int read(void)
{
    int s = 0, w = 1;
    char ch = getchar();
    for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') w = -1;
    for(; ch <= '9' && ch >= '0'; ch = getchar()) s = s * 10 + ch - '0';
    return s * w;
}

inline void add(int x, int y)
{
    e[++cnt].x = x;
    e[cnt].y = y;
    e[cnt].nxt = head[x];
    head[x] = cnt;
}

int bfs(void)
{
    for(int i = 1; i <= n; i++)
    {
        if(in[i] < 3)
        {
            Q.push(i);
            vis[i] = true;
        }
    }
    for(; !Q.empty(); )
    {
        int x = Q.front();
        Q.pop();
        for(int i = head[x]; i != -1; i = e[i].nxt)
        {
            int y = e[i].y;
            if(vis[y]) continue;
            in[y]--;
            if(in[y] < 3)
            {
                Q.push(y);
                vis[y] = true;
            }
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) if(!vis[i]) ans ^= i;
    return ans;
}

bool cmp(Side rr, Side tt)
{
    return rr.fr == tt.fr ? rr.to < tt.to : rr.fr < tt.fr;
}

int main()
{
    freopen("asm_game.in", "r", stdin);
    freopen("asm_game.out", "w", stdout);
    memset(head, -1, sizeof(head));
    n = read(); m = read();
    for(int i = 1; i <= m; i++)
    {
        fr = read(); to = read();
        if(fr > to) swap(fr, to);
        a[i].fr = fr;
        a[i].to = to;
    }
//    sort(a + 1, a + m + 1, cmp);
//    for(int i = 1; i <= m; i++) if(a[i].fr == a[i - 1].fr && a[i].to == a[i - 1].to) chong[i] = true;
    // int cnt = unique(a + 1, a + m + 1, cmp) - a - 1;
    // cout << cnt << '\n';
    for(int i = 1; i <= m; i++)
    {
        if(chong[i]) continue;
        fr = a[i].fr;
        to = a[i].to;
        add(fr, to);
        add(to, fr);
        in[fr]++;
        in[to]++;
    }
    cout << bfs() << '\n';
    return 0;
}