Created
August 9, 2013 03:41
-
-
Save NonWhite/6191012 to your computer and use it in GitHub Desktop.
POJ 2425 [A chess game]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <sstream> | |
| #include <bitset> | |
| #include <cstdio> | |
| #include <string> | |
| #include <cstring> | |
| #include <vector> | |
| #include <queue> | |
| #include <stack> | |
| #include <set> | |
| #include <map> | |
| #include <algorithm> | |
| #include <cmath> | |
| #include <cstdlib> | |
| #include <cctype> | |
| #include <numeric> | |
| #include <list> | |
| #define FOR(i,A) for(typeof (A).begin() i = (A).begin() ; i != (A).end() ; i++) | |
| #define mp make_pair | |
| #define debug( x ) cout << #x << " = " << x << endl | |
| #define clr(v,x) memset( v, x , sizeof v ) | |
| #define all(x) (x).begin() , (x).end() | |
| #define rall(x) (x).rbegin() , (x).rend() | |
| #define ones(x) __builtin_popcount( x ) | |
| #define f(i,a,b) for(int i = a ; i < b ; i++) | |
| #define fd(i,a,b) for(int i = a ; i >= b ; i--) | |
| #define PI acos( -1.0 ) | |
| #define EPS 1E-9 | |
| #define TAM 1010 | |
| using namespace std; | |
| typedef pair<int,int> ii ; | |
| typedef long long ll ; | |
| typedef long double ld ; | |
| typedef pair<int,ii> pii ; | |
| int v[ TAM ] ; | |
| vector<int> g[ TAM ] ; | |
| int n ; | |
| void dfs( int x ){ | |
| if( v[ x ] != -1 ) return ; | |
| if( g[ x ].size() == 0 ){ v[ x ] = 0 ; return ; } | |
| int used[ n ] ; | |
| clr( used , 0 ) ; | |
| f( i , 0 , g[ x ].size() ){ | |
| int u = g[ x ][ i ] ; | |
| dfs( u ) ; | |
| used[ v[ u ] ] = true ; | |
| } | |
| f( i , 0 , n && v[ x ] < 0 ) if( !used[ i ] ) v[ x ] = i ; | |
| } | |
| int main(){ | |
| int m , x ; | |
| while( scanf("%d" , &n ) == 1 ){ | |
| if( n == 0 ) break ; | |
| f( i , 0 , n ) g[ i ].clear() , v[ i ] = -1 ; | |
| f( i , 0 , n ){ | |
| scanf("%d" , &m ) ; | |
| f( j , 0 , m ){ | |
| scanf("%d" , &x ) ; | |
| g[ i ].push_back( x ) ; | |
| } | |
| } | |
| f( i , 0 , n ) if( v[ i ] < 0 ) dfs( i ) ; | |
| while( scanf("%d" , &m ) == 1 ){ | |
| if( m == 0 ) break ; | |
| int R = 0 ; | |
| f( i , 0 , m ) scanf("%d" , &x ) , R ^= v[ x ] ; | |
| printf("%s\n" , R ? "WIN" : "LOSE" ) ; | |
| } | |
| } | |
| return 0 ; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment