题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1524
1 #include<stdio.h> 2 #include<cstring> 3 using namespace std; 4 const int M = 10000000;// 5 const int N = 1005; 6 int sg[N], head[N]; 7 int cnt; 8 9 struct node{ 10 int from; 11 int to; 12 int next; 13 }edge[M]; 14 15 void addedge( int from, int to){ 16 edge[cnt].from = from; 17 edge[cnt].to = to; 18 edge[cnt].next = head[from];//同一个父节点引出的边 19 head[from] = cnt++; 20 } 21 22 void init(){ 23 cnt = 0;//总边数 24 memset(head,-1,sizeof(head)); 25 memset(sg,-1,sizeof(sg)); 26 } 27 28 int mex(int n){ 29 bool g[N]; 30 memset(g,false,sizeof(g)); 31 if( sg[n] != -1 ) 32 return sg[n]; 33 for(int i = head[n];i != -1; i = edge[i].next){ 34 if( sg[edge[i].to] == -1 ) 35 sg[edge[i].to] = mex(edge[i].to); 36 g[sg[edge[i].to]] = true; 37 } 38 for( int i = 0; i < N; ++i) 39 if(!g[i]) 40 return i; 41 } 42 43 int main(){ 44 int n, m, tmp; 45 while(~scanf("%d",&n)){ 46 init(); 47 for(int i = 0; i < n; ++i){ 48 scanf("%d",&m); 49 for( int j = 0; j < m; ++j){ 50 scanf("%d",&tmp); 51 addedge(i,tmp);//建图 52 } 53 } 54 while(~scanf("%d",&m)&&m){ 55 int ans = 0; 56 for( int i = 0; i < m; ++i){ 57 scanf("%d",&tmp); 58 ans = ans ^ mex(tmp); 59 } 60 puts(ans?"WIN":"LOSE"); 61 } 62 } 63 return 0; 64 }
百题留念
时间: 2024-12-29 11:22:01