CF1776J.Italian Data Centers

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 ss in the old data center, the new data center contains two servers s1s_1 and s2s_2 of the same color as ss . A wire is placed connecting the two servers s1s_1 and s2s_2 .
  • For each wire connecting servers ss and tt in the old data center: if ss and tt have the same color, then a wire is placed in the new data center connecting s1s_1 and t1t_1 and another wire connecting s2s_2 and t2t_2 ; otherwise, a wire is placed in the new data center connecting s1s_1 and t2t_2 and another one connecting s2s_2 and t1t_1 .

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 nn servers (indexed by 1,2,,n1, \, 2, \, \dots, \, n ) and mm wires connecting them. The organization wants to know how good their data center will be after kk years, so you should determine the diameter of the data center SWERC will have in kk 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 nn , mm and kk ( 2n1002 \leq n \leq 100 , n1mn(n1)/2n - 1 \leq m \leq n (n - 1) / 2 , 0k1000 \leq k \leq 100 ) — the number of servers, the number of wires, and the number of years to consider.

The second line contains nn integers c1,c2,,cnc_1, \, c_2, \, \dots, \, c_n ( 1ci31 \leq c_i \leq 3 ) — cic_i is the color of server ii (where 11 stands for green, 22 for white and 33 for red).

Each of the next mm lines contains two integers sis_i and tit_i ( 1si,tin1 \leq s_i, t_i \leq n ) — the two servers the ii -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 kk years.

输入输出样例

  • 输入#1

    3 3 0
    1 2 3
    1 2
    2 3
    3 1

    输出#1

    1
  • 输入#2

    3 3 1
    1 2 3
    1 2
    2 3
    3 1

    输出#2

    2
  • 输入#3

    3 3 2
    1 2 1
    1 2
    2 3
    3 1

    输出#3

    3
  • 输入#4

    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

    输出#4

    53

说明/提示

In the first sample, the Italian data center is the following:

The distance between any pair of servers is 11 so the diameter is 11 .

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):

Consider the highlighted servers. The distance between them is 22 and there is no pair of servers with greater distance, so the diameter is 22 .

In the third sample, the data center after one year is the following:

After one more year:

Consider the highlighted servers. The distance between them is 33 and there is no pair of servers with greater distance, so the diameter is 33 .

首页