forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2425 - A Chess Game.cpp
62 lines (44 loc) · 1.16 KB
/
2425 - A Chess Game.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
vector<int> L[1000];
int memo[1000];
int solve(int pos){
int &ret = memo[pos];
if(ret == -1){
ret = 0;
bool have[1000];
memset(have,false,sizeof have);
for(int i = L[pos].size() - 1;i >= 0;--i)
have[ solve(L[pos][i]) ] = true;
while(have[ret]) ++ret;
}
return ret;
}
int main(){
int N,M;
while(scanf("%d",&N) == 1){
for(int i = 0;i < N;++i)
L[i].clear();
for(int i = 0,sz,x;i < N;++i){
scanf("%d",&sz);
for(int j = 0;j < sz;++j){
scanf("%d",&x);
L[i].push_back(x);
}
}
memset(memo,-1,sizeof memo);
while(true){
scanf("%d",&M);
if(M == 0) break;
int ans = 0;
for(int i = 0,x;i < M;++i){
scanf("%d",&x);
ans ^= solve(x);
}
puts(ans == 0? "LOSE" : "WIN");
}
}
return 0;
}