#P15169. [SWERC 2022] Italian Data Centers
[SWERC 2022] Italian Data Centers
题目描述
An Italian data center consists of a set of servers, each colored green, white, or red, and a set of wires connecting them. Each wire connects two distinct servers and two servers are connected by at most one wire. Additionally, the data center is connected, i.e. there is a way to transmit information between any two servers through a sequence of wires.
To judge all of the contestant submissions, SWERC has an Italian data center. Since every year the number of contestants doubles, the data center needs to grow to adapt to the extra load. To address this, SWERC builds a new data center based on the previous year's one by following these steps:
- For each server in the old data center, the new data center contains two servers and of the same color as . A wire is placed connecting the two servers and .
- For each wire connecting servers and in the old data center: if and have the same color, then a wire is placed in the new data center connecting and and another wire connecting and ; otherwise, a wire is placed in the new data center connecting and and another one connecting and .
One can show that if the old data center is connected than the new data center is also connected.
You are given the Italian data center that SWERC currently has, which contains servers (indexed by ) and wires connecting them. The organization wants to know how good their data center will be after years, so you should determine the diameter of the data center SWERC will have in years. The diameter of the data center is the largest distance between any two servers, i.e. the shortest number of wires that have to be used to transmit something between the two servers.
输入格式
The first line contains three integers , and ( , , ) — the number of servers, the number of wires, and the number of years to consider.
The second line contains integers ( ) — is the color of server (where stands for green, for white and for red).
Each of the next lines contains two integers and ( ) — the two servers the -th wire connects.
It is guaranteed that the data center is connected, the endpoints of each wire are distinct, and that there are no repeated wires.
输出格式
Print the diameter of SWERC's data center after years.
3 3 0
1 2 3
1 2
2 3
3 1
1
3 3 1
1 2 3
1 2
2 3
3 1
2
3 3 2
1 2 1
1 2
2 3
3 1
3
8 14 100
3 3 2 2 1 2 2 1
2 7
1 5
7 8
4 6
2 8
1 8
2 6
6 7
1 6
1 4
3 5
1 3
4 5
5 7
53
提示
In the first sample, the Italian data center is the following:
:::align{center}
:::
The distance between any pair of servers is so the diameter is .
In the second sample, the initial Italian data center is the one from the first sample.
After one year we obtain the following (where the numbers indicate which copy the server refers to):
:::align{center}
:::
Consider the highlighted servers. The distance between them is and there is no pair of servers with greater distance, so the diameter is .
In the third sample, the data center after one year is the following:
:::align{center}
:::
After one more year:
:::align{center}
:::
Consider the highlighted servers. The distance between them is and there is no pair of servers with greater distance, so the diameter is .