CF2032A Circuit
题目描述
Alice 刚才制作了一个有 $n$ 盏灯和 $2n$ 个开关的电路,电路中的每个元件(即每盏灯或每个开关)都有两个状态:开或者关。灯和开关按照下列方式排序:
- 每盏灯连接**两个**开关。
- 每个开关与**一盏**灯连接,且**不知道**灯和开关的连接关系。
- 如果所有开关都处于关闭状态,则所有的灯也会关闭。
- 如果开关状态发生改变(即关变成开或开变成关),则相连的灯也会改变状态。
Alice 把只展示了 $2n$ 盏灯的电路拿给姐姐 Iris 看,并给了她一个谜题:能够开启灯的数量的最小值和最大值分别是多少?
Iris 非常了解她妹妹的小把戏,很快就给出了正确答案。你也能做到吗?
输入格式
每个测试点有多组测试数据。第一行包含整数 $t(1\leq t\leq 500)$,表示测试数据个数。
每个测试数据的第一行为一个整数 $n(1\leq n\leq 50)$,表示灯的数量。
第二行包含 $2n$ 个整数 $a_1,a_2,\dots, a_{2n}(1\leq a_i\leq 1)$,表示开关的状态,其中 $a_i=0$ 表示第 $i$ 个开关处于关闭状态,$a_i=1$ 表示第 $i$ 个开关处于开启状态。
输出格式
对于每组测试数据,输出两个整数,分别表示能够开启灯的数量的最小值和最大值。
### 样例解释
对于第一个测试数据,电路中只有一盏灯,且开关均处于关闭状态,因此灯一定处于关闭状态。
对于第二个测试数据,电路中只有一盏灯,但其中一个开关处于开启状态,因此灯一定处于开启状态。
对于第三个测试数据,电路中只有一盏灯,且前两个开关都处于开启状态,这说明这盏灯被两个开关分别切换了一次状态,所以灯处于关闭状态。
对于第四个测试数据,让所有灯都处于关闭状态的可能为:
- 开关 $1$ 和开关 $4$ 连接电灯 $1$。由于这两个开关都关闭,所以这盏灯也关闭。
- 开关 $2$ 和开关 $6$ 连接电灯 $2$。由于这两个开关都关闭,所以这盏灯也关闭。
- 开关 $3$ 和开关 $5$ 连接电灯 $3$。由于这两个开关都开启,所以这盏灯的状态被切换了两次,处于关闭状态。
让两盏灯处于开启状态的可能为:
- 开关 $1$ 和开关 $2$ 连接电灯 $1$。由于这两个开关都关闭,所以这盏灯也关闭。
- 开关 $3$ 和开关 $4$ 连接电灯 $1$。由于开关 $3$ 开启而开关 $4$ 关闭,所以这盏灯开启。
- 开关 $5$ 和开关 $6$ 连接电灯 $3$。由于开关 $5$ 开启而开关 $6$ 关闭,所以这盏灯开启。
说明/提示
In the first test case, there is only one light in the circuit, and no switch is on, so the light is certainly off.
In the second test case, there is only one light in the circuit, but one switch connected to it is on, so the light is on.
In the third test case, there is only one light in the circuit, and both switches are on, so the light is off as it was toggled twice.
In the fourth test case, to have no lights on, the switches can be arranged in this way:
- Switch $ 1 $ and switch $ 4 $ are connected to light $ 1 $ . Since both switches are off, light $ 1 $ is also off.
- Switch $ 2 $ and switch $ 6 $ are connected to light $ 2 $ . Since both switches are off, light $ 2 $ is also off.
- Switch $ 3 $ and switch $ 5 $ are connected to light $ 3 $ . Both switches are on, so light $ 3 $ is toggled twice from its initial off state, and thus also stays off.
And to have $ 2 $ lights on, the switches can be arranged in this way:
- Switch $ 1 $ and switch $ 2 $ are connected to light $ 1 $ . Since both switches are off, light $ 1 $ is also off.
- Switch $ 3 $ and switch $ 4 $ are connected to light $ 2 $ . Since switch $ 3 $ is on and switch $ 4 $ is off, light $ 2 $ is toggled once from its initial off state, so it is on.
- Switch $ 5 $ and switch $ 6 $ are connected to light $ 3 $ . Since switch $ 5 $ is on and switch $ 6 $ is off, light $ 3 $ is toggled once from its initial off state, so it is on.