比赛 |
Asm.Def战记之圣地亚哥“杯2015 |
评测结果 |
AAAAAAAAAA |
题目名称 |
Asm.Def的游戏 |
最终得分 |
100 |
用户昵称 |
氢氦 |
运行时间 |
0.060 s |
代码语言 |
C++ |
内存使用 |
25.96 MiB |
提交时间 |
2019-10-23 17:55:47 |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using std::queue;
const int maxn = 1e5 + 5;
const int maxm = 5e5 + 5;
bool vis[maxn];
int n, m, tot, head[maxn], deg[maxn];
template <class T>
inline T read(T &x) {
x = 0; int w = 1, ch = getchar();
for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') w = -1;
for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
return x *= w;
}
struct Edge {
int from, to, nxt;
Edge(int _fr, int _to, int _nxt) {
this -> from = _fr;
this -> to = _to;
this -> nxt = _nxt;
} Edge() {}
}edge[maxm << 1];
void add(int from, int to) {edge[++tot] = Edge(from, to, head[from]), head[from] = tot;}
void nmd_topo() {
queue<int>q;
for (int i = 1; i <= n; i++)
if (deg[i] < 3) vis[i] = true, q.push(i);
while (!q.empty()) {
int u = q.front();
q.pop();
for (int i = head[u]; i; i = edge[i].nxt) {
int v = edge[i].to;
if (vis[v]) continue;
deg[v]--;
if (deg[v] < 3) vis[v] = true, q.push(v);
}
}
}
int main() {
freopen("asm_game.in", "r", stdin);
freopen("asm_game.out", "w", stdout);
read(n), read(m); int x, y;
for (int i = 1; i <= m; i++) {
read(x), read(y);
add(x, y), add(y, x);
++deg[x], ++deg[y];
}
nmd_topo();
int ans = 0;
for (int i = 1; i <= n; i++) {
if (vis[i]) continue;
ans = ans ^ i;
}
printf("%d\n", ans);
return 0;
}
/*
6 10
1 2
1 3
1 4
2 3
2 4
3 4
5 2
5 3
5 6
6 2
复杂度O(玄学)
*/