Files
python/TangDou/AcWing_TiGao/T5/GameTheory/1319.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

57 lines
1.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 2010, M = 6010;
// SG函数模板题
int n, m, k;
int f[N];
int h[N], e[M], ne[M], idx;
void add(int a, int b) {
e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
int sg(int u) {
//记忆化搜索
if (~f[u]) return f[u];
//找出当前结点u的所有出边,看看哪个sg值没有使用过
set<int> S;
for (int i = h[u]; ~i; i = ne[i])
S.insert(sg(e[i]));
//找到第一个没有出现的过的自然数, 0,1,2,3,4,...
for (int i = 0;; i++)
if (S.count(i) == 0) {
f[u] = i;
break;
}
return f[u];
}
int main() {
memset(h, -1, sizeof h);
cin >> n >> m >> k;
while (m--) {
int a, b;
cin >> a >> b;
add(a, b);
}
memset(f, -1, sizeof f); //初始化sg函数的结果表
int res = 0;
while (k--) {
int u;
cin >> u;
res ^= sg(u); //计算每个出发点的sg(u),然后异或在一起
}
if (res) //所有出发点的异或和不等于0,先手必胜
puts("win");
else //所有出发点的异或和等于0,先手必败
puts("lose");
return 0;
}