比赛 Asm.Def战记之圣地亚哥“杯2015 评测结果 AAAAAAAAAA
题目名称 Asm.Def的游戏 最终得分 100
用户昵称 liujiaqi 运行时间 0.064 s
代码语言 C++ 内存使用 22.24 MiB
提交时间 2019-10-23 17:42:49
显示代码纯文本
#include <queue>
#include <cstdio>
#include <algorithm>
int v, c;
template <class T> T read(T& x) {
	x = 0; v = 1; c = getchar();
	for (; c < '0' || c > '9'; c = getchar()) if (c == '-') v = -1;
	for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
	return x *= v;
}
const int N = 500010;
int n, m, x, y, ans, du[N];
int cnt, head[N];
bool vis[N], inq[N];
struct Edge {
	int y, nxt;
} e[N];
inline void add(int x, int y) {
	e[++cnt].y = y; e[cnt].nxt = head[x]; head[x] = cnt;
}
std::queue <int> q;
void topo() {
	for (; !q.empty(); ) {
		int x = q.front(); q.pop();
		vis[x] = 1;
		for (int i = head[x]; i; i = e[i].nxt) {
			int y = e[i].y;
			--du[y];
			if (!vis[y] && !inq[y] && du[y] < 3) {
				inq[y] = 1; q.push(y);
			}
		}
	}
}
int main() {
	freopen("asm_game.in", "r", stdin);
	freopen("asm_game.out", "w", stdout);
	read(n); read(m);
	for (int i = 1; i <= m; ++i) {
		read(x); read(y);
		add(x, y); add(y, x);
		++du[x]; ++du[y];
	}
	for (int i = 1; i <= n; ++i) {
		if (du[i] < 3) {
			inq[i] = 1; q.push(i);
		}
	}
	topo();
	for (int i = 1; i <= n; ++i) {
		if (!vis[i]) ans ^= i;
	}
	printf("%d\n", ans);
	return 0;
}