#P9413. 「NnOI R1-T2」风屿
「NnOI R1-T2」风屿
Background
"Named after the wind, the isles sing together." — Wind Isle.
Problem Description
Wind Isle is an archipelago with rows and columns. The cell in row and column is denoted as .
The gravity system of Wind Isle is very strange. The gravity coefficient of is . Here, and are two known arrays of lengths and .
We say islands and are adjacent if and only if . We say and are connected if and only if at least one of the following holds:
-
and are adjacent, and .
-
There exists another island such that is connected to and is connected to . That is, the connected relation is transitive.
We define an unordered set of distinct islands to be a same-color connected component if and only if every pair of islands in the set is connected.
Find the largest same-color connected component, and output its size and the number of such components.
Input Format
This problem has multiple test cases. The first line contains a positive integer , representing the number of testdata groups in this test.
For each test case:
The first line contains and , representing the number of rows and columns of Wind Isle.
The next line contains integers, representing array .
The next line contains integers, representing array .
Output Format
Output lines. Each line contains the answer for that test case (the maximum component size and the count).
3
3 4
1 2 2
1 2 3 4
4 5
1 2 2 3
2 3 3 3 4
6 7
1 1 2 2 3 4
1 2 2 2 3 3 3
2 4
6 1
6 4
Hint
Sample Explanation
For sample :
For the first test case, the gravity coefficients are as follows:
2 3 4 5
3 4 5 6
3 4 5 6
2 3 4 5
* # ? .
* # ? .
The cells marked by symbols form the largest same-color connected components. The size is , and there are such components.
Constraints
For of the data, .
For another of the data, all are equal.
For another of the data, the answer to the second question is guaranteed to be .
For another of the data, . The test points represented by these four subtasks do not include each other.
For of the data, , , .
Source
| Item | People |
|---|---|
| idea | Kevin0501 |
| std | |
| data | EstasTonne |
| check | |
| solution | Kevin0501 |
Translated by ChatGPT 5