CF1776J.Italian Data Centers

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

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.

一个意大利数据中心由一组服务器(每台服务器被涂成绿色、白色或红色)以及连接它们的一组网线组成。每条网线连接两台不同的服务器,且任意两台服务器之间至多有一条网线相连。此外,该数据中心是连通的,即任意两台服务器之间均存在一条由若干网线构成的路径,从而可实现信息传输。

为评判所有参赛选手的提交程序,SWERC 拥有一个意大利数据中心。由于每年参赛选手人数翻倍,该数据中心需不断扩容以应对额外负载。为此,SWERC 每年基于上一年的数据中心,按如下步骤构建新的数据中心:

  • 对旧数据中心中的每台服务器 ss,新数据中心中包含两台与其颜色相同的服务器 s1s_1 和 s2s_2,并在 s1s_1 与 s2s_2 之间连接一条网线;
  • 对旧数据中心中任意一条连接服务器 ss 与 tt 的网线:若 ss 与 tt 颜色相同,则在新数据中心中连接 s1s_1 与 t1t_1,并另连接 s2s_2 与 t2t_2;否则(即 ss 与 tt 颜色不同),则在新数据中心中连接 s1s_1 与 t2t_2,并另连接 s2s_2 与 t1t_1。

可以证明:若旧数据中心是连通的,则新数据中心也必然是连通的。

现给定 SWERC 当前拥有的意大利数据中心,其包含 nn 台服务器(编号为 1, 2, …, n1,\,2,\,\dots,\,n)以及 mm 条连接它们的网线。组织方希望了解其数据中心在 kk 年后的性能表现,因此你需要计算 kk 年后数据中心的直径。数据中心的直径定义为任意两台服务器之间的最大距离,即这两台服务器间信息传输所需经过的最短网线数目。

输入格式

The first line contains three integers nn, mm and kk (2≤n≤1002 \leq n \leq 100, n−1≤m≤n(n−1)/2n - 1 \leq m \leq n (n - 1) / 2, 0≤k≤1000 \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 (1≤ci≤31 \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 (1≤si,ti≤n1 \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.

第一行包含三个整数 nn、mm 和 kk(2≤n≤1002 \leq n \leq 100,n−1≤m≤n(n−1)/2n - 1 \leq m \leq n (n - 1) / 2,0≤k≤1000 \leq k \leq 100)——分别表示服务器数量、网线数量以及需考虑的年数。

第二行包含 nn 个整数 c1, c2, …, cnc_1, \, c_2, \, \dots, \, c_n(1≤ci≤31 \leq c_i \leq 3)——其中 cic_i 表示第 ii 台服务器的颜色(11 表示绿色,22 表示白色,33 表示红色)。

接下来的 mm 行中,每行包含两个整数 sis_i 和 tit_i(1≤si,ti≤n1 \leq s_i, t_i \leq n)——表示第 ii 条网线所连接的两台服务器。

保证数据中心是连通的,每条网线的两个端点互不相同,且不存在重复的网线。

输出格式

Print the diameter of SWERC's data center after kk years.

输出 SWERC 数据中心在 kk 年后的直径。

输入输出样例

  • 输入#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.

在第一个样例中,意大利数据中心如下所示:

任意两台服务器之间的距离均为 11,因此直径为 11。

在第二个样例中,初始的意大利数据中心与第一个样例相同。

一年后,我们得到如下结构(其中数字表示该服务器所属的副本):

考虑图中高亮显示的两台服务器,它们之间的距离为 22,且不存在距离更大的服务器对,因此直径为 22。

在第三个样例中,一年后的数据中心如下所示:

再过一年后:

考虑图中高亮显示的两台服务器,它们之间的距离为 33,且不存在距离更大的服务器对,因此直径为 33。

输入解题思路,AI测评打分。不知道怎么写?

首页