标签:
Description
Input
Output
Sample Input
2 3 0 0 0 1 1 1 1 2 1 3 2 1 2 3 3 1 3 2 0 0 3 0 0 0 1 0 1 1 2 2 1 0 0
Sample Output
4 Oh,it‘s impossible~!!
Hint
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> #include<vector> #include<map> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define ls i<<1 #define rs ls | 1 #define mid ((ll+rr)>>1) #define pii pair<int,int> #define MP make_pair typedef long long LL; const long long INF = 1e18; const double Pi = acos(-1.0); const int N = 1e5+10, M = 1e6+11, inf = 2e9, mod = 1e6+3; int a[330][330], n; int gauss() { int i,j; for(i = 0, j = 0; j < n && i < n; ++j) { int k = i; for(; k < n; ++k) if(a[k][j]) break; if(a[k][j]) { for(int u = 0; u <= n; ++u) swap(a[k][u],a[i][u]); for(int u = i + 1; u < n; ++u) { if(a[u][j]) for(int kk = 0; kk <= n; ++kk) a[u][kk] ^= a[i][kk]; } ++i; } } for(j = i; j < n; ++j) { if(a[j][n]) return -1; } return 1LL << (n - i); } int main() { int k; scanf("%d",&k); while(k--) { memset(a,0,sizeof(a)); scanf("%d",&n); for(int i = 0; i < n; ++i) scanf("%d",&a[i][n]); for(int i = 0; i < n; ++i) { int x; scanf("%d",&x); a[i][n] ^= x; a[i][i] = 1; } int u,v; while(scanf("%d%d",&u,&v) && u + v) { a[v-1][u-1] = 1; } int ans = gauss(); if(ans == -1) puts("Oh,it‘s impossible~!!");else printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zxhl/p/5818682.html