QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#4608. 小 Y 和地铁

统计

小Y是一个爱好旅行的OIer。一天,她来到了一个新的城市。由于不熟悉那里的交通系统,她选择了坐地铁。

她发现每条地铁线路可以看成平面上的一条曲线,不同线路的交点处一定会设有换乘站 problem_4608_1.webp 。通过调查得知,没有线路是环线,也没有线路与自身相交。任意两条不同的线路只会在若干个点上相交,没有重合的部分,且没有三线共点的情况。即,如图所示的情况都是不存在的:

problem_4608_2.webp

小Y坐着地铁 $0$ 号线,路上依次经过了 $n$ 个换乘站。她记下了每个换乘站可以换乘的线路编号,发现每条线路与她所乘坐的线路最多只有 $2$ 个换乘站。现在小Y想知道,除掉她经过的换乘站以外,这个城市里最少有几个换乘站。只有你告诉她正确的答案,她才会答应下次带你去玩呢。

输入格式

从标准输入读入数据。

请注意本题有多组输入数据。

输入数据的第一行是一个整数 $T$,表示输入数据的组数。接下来依次给出每组数据。

对于每组数据,第一行是一个整数 $n$,表示小Y经过的换乘站的数目。第二行为 $n$ 个用空格隔开的整数,依次表示每个换乘站的可以换乘的线路编号。这些编号都在 $1$ ~ $n$ 之内。

输出格式

输出到标准输出。

对于每组输入数据,输出一行一个整数,表示除掉这 $n$ 个换乘站之外,最少有几个换乘站。

样例一

input

4
4
1 2 1 2
8
1 2 3 4 1 2 3 4
5
5 4 3 3 5
8
1 2 3 4 1 3 2 4

output

0
0
0
1

explanation

对于样例的前两组数据,一种可能的最优答案如下图所示。

problem_4608_3.png

限制与约定

一共有 50 个测试点,每个测试点 2 分。你只有在答案完全正确时才能得到该测试点的全部分数,否则不得分。

对于所有测试点,以及对于样例,$1 \le T \le 100, 1 \le n \le 44$。对于每个测试点,$n$ 的范围如下表:

测试点编号$1 \le n \le$测试点编号$1 \le n \le$
122632
232733
342833
452934
563034
683135
793235
8103336
9113436
10123537
11133637
12143738
13153838
14163939
15174039
16204140
17224240
18244341
19264441
20284542
21304642
22304743
23314843
24314944
25325044
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.