#P10683. [COTS 2024] 划分 Particija

    ID: 12179 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2024O2优化二分图COCI(克罗地亚)

[COTS 2024] 划分 Particija

Background

Translated from Izborne Pripreme 2024 (Croatian IOI/CEOI Team Selection) D2T1。1s,512M\texttt{1s,512M}

Problem Description

You are given a positive integer NN

A partition of the set {1,2,,N}\{1, 2, \ldots, N\} is a family of non-empty sets such that:

  • 1iN\forall 1\le i\le Nii appears in exactly one set。

For example, {{1,3},{2,4},{5}}\{\{1,3\},\{2,4\},\{5\}\} is a partition of the set {1,2,3,4,5}\{1, 2, 3, 4, 5\}

A partition can be represented by an array [x1,x2,,xN][x_1, x_2, \ldots, x_N]。Element ii and element jj are in the same set if and only if xi=xjx_i = x_j。The partition {{1,3},{2,4},{5}}\{\{1,3\},\{2,4\},\{5\}\} mentioned above can be represented by [1,2,1,2,3][1, 2, 1, 2, 3] or [5,1,5,1,4][5, 1, 5, 1, 4]

Patricija has two partitions: the first one is represented by [a1,a2,,aN][a_1, a_2, \ldots, a_N],and the second one is represented by [b1,b2,,bN][b_1, b_2, \ldots, b_N]

Patricija wants to know the answer to the following question: if she uses sets from these two partitions to construct a partition of the set {1,2,,N}\{1, 2, \ldots, N\},what is the minimum number of sets needed。

Given a parameter k{0,1,2}k\in \{0,1,2\}:

  • When k=0k=0,you need to answer the original question。
  • When k=1k=1,you are allowed to change at most one number among the 2N2N numbers (a1,,aN,b1,,bNa_1,\cdots,a_N,b_1,\cdots,b_N),and minimize the minimum number of sets needed to construct such a partition。
  • When k=2k=2,you are allowed to change at most one number among the 2N2N numbers (a1,,aN,b1,,bNa_1,\cdots,a_N,b_1,\cdots,b_N),and maximize the minimum number of sets needed to construct such a partition。

Note that after your modification, you must ensure that 1iN\forall 1\le i\le N1ai,biN1\le a_i,b_i\le N

Input Format

This problem contains multiple test cases within a single input file.

The first line contains two integers T,kT,k,representing the number of test cases and the parameter.

Then TT test cases follow.

For each test case, the input contains three lines.

The first line contains a positive integer NN,as described above.

The second line contains NN positive integers, representing a1,a2,,aNa_1,a_2,\cdots,a_N

The third line contains NN positive integers, representing b1,b2,,bNb_1,b_2,\cdots,b_N

Output Format

For each test case, output one line with one integer, representing the required answer。

2 0
4 
1 1 2 3
1 2 3 3
7
1 1 1 1 2 3 4
1 2 3 4 4 4 4
2
4
3 1
4
1 1 2 3
1 2 3 3
4
1 1 1 1
1 2 3 3
7
1 1 1 1 2 3 4
1 2 3 4 4 4 4
2
1
2
3 2
4 
1 1 2 3
1 2 3 3
4
1 1 1 3
1 2 3 3
7
1 1 1 2 3 4 5
1 2 3 4 4 4 4
3
3
4

Hint

Sample Explanation

Explanation for sample 11:

For the first test case, the first partition is {{1,2},{3},{4}}\{\{1,2\},\{3\},\{4\}\},and the second partition is {{1},{2},{3,4}}\{\{1\},\{2\},\{3,4\}\}。Choosing {1,2},{3,4}\{1,2\},\{3,4\} is enough。

For the second test case, the first partition is {{1,2,3,4},{5},{6},{7}}\{\{1,2,3,4\},\{5\},\{6\},\{7\}\},and the second partition is {{1},{2},{3},{4,5,6,7}}\{\{1\},\{2\},\{3\},\{4,5,6,7\}\}。Choosing either the first partition or the second partition is enough。

Constraints

For 100%100\% of the data, it is guaranteed that:

  • 1T2×1051\le T\le 2\times 10^5k{0,1,2}k\in \{0,1,2\}
  • 1ai,biN1\le a_i,b_i\le N
  • 1N,N2×1051\le N,\sum N\le 2\times 10^5
Subtask ID Score Constraints
11 77 k=0,N8,2N105k=0,N\le 8,\sum 2^N\le 10^5
22 2323 k=0k=0
33 1515 k=1,N1000,N2106k=1,N\le 1\, 000,\sum N^2\le 10^6
44 1616 k=1k=1
55 1919 k=2,N1000,N2106k=2,N\le 1\, 000,\sum N^2\le 10^6
66 2020 k=2k=2

Translated by ChatGPT 5