记录编号 580321 评测结果 A
题目名称 [POJ 1830]开关问题 最终得分 100
用户昵称 Gravataryrtiop 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2023-07-21 21:41:14 内存使用 0.00 MiB
显示代码纯文本
#include <bits/stdc++.h>

const int maxn = 105;
int n, a[maxn];

void work() {
	scanf("%d", &n);
	for(int i = 1;i <= n;++ i)
		scanf("%d", &a[i]);
	for(int i = 1;i <= n;++ i) {
		int x; scanf("%d", &x);
		a[i] ^= x; a[i] |= 1 << i;
	}
	int x, y, ans = 1;
	while(~ scanf("%d %d", &x, &y)&&x&&y)
		a[y] |= 1 << x;
	for(int i = 1;i <= n;++ i) {
		for(int j = i + 1;j <= n;++ j)
			if(a[j] > a[i])
				std::swap(a[i], a[j]);
		if(a[i] == 0) { ans = 1 << (n - i + 1); break ; }
		if(a[i] == 1) { ans = 0; break ; }
		for(int k = n;k;-- k)
			if(a[i] >> k & 1) {
				for(int j = 1;j <= n;++ j)
					if(j != i&&(a[j] >> k & 1))
						a[j] ^= a[i];
				break ;
			}
	}
	if(!ans)
		puts("Oh,it's impossible~!!");
	else
		printf("%d\n", ans);
	return ;
}

int main() {
	freopen("switch.in", "r", stdin);
	freopen("switch.out", "w", stdout);
	int T; scanf("%d", &T);
	while(T --)
		work();
	return 0;
}