CF986A.Fair

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Some company is going to hold a fair in Byteland. There are nn towns in Byteland and mm two-way roads between towns. Of course, you can reach any town from any other town using roads.

There are kk types of goods produced in Byteland and every town produces only one type. To hold a fair you have to bring at least ss different types of goods. It costs d(u,v)d(u,v) coins to bring goods from town uu to town vv where d(u,v)d(u,v) is the length of the shortest path from uu to vv. Length of a path is the number of roads in this path.

The organizers will cover all travel expenses but they can choose the towns to bring goods from. Now they want to calculate minimum expenses to hold a fair in each of nn towns.

某公司将在比特兰(Byteland)举办一场展销会。比特兰共有 nn 座城镇和 mm 条连接城镇的双向道路。显然,任意两座城镇之间均可通过道路相互到达。

比特兰共生产 kk 种商品,且每座城镇仅生产其中一种。要举办一场展销会,必须至少汇集 ss 种不同类别的商品。将商品从城镇 uu 运送至城镇 vv 的花费为 d(u,v)d(u,v) 枚金币,其中 d(u,v)d(u,v) 表示 uu 到 vv 的最短路径长度(即该路径所含道路的数量)。

主办方将承担全部运输费用,但他们可自主选择从哪些城镇调运商品。现在,他们希望计算在每一座城镇举办展销会所需的最小总费用。

输入格式

There are 44 integers nn, mm, kk, ss in the first line of input (1≤n≤1051 \le n \le 10^{5}, 0≤m≤1050 \le m \le 10^{5}, 1≤s≤k≤min(n,100)1 \le s \le k \le min(n, 100)) — the number of towns, the number of roads, the number of different types of goods, the number of different types of goods necessary to hold a fair.

In the next line there are nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤k1 \le a_{i} \le k), where aia_i is the type of goods produced in the ii-th town. It is guaranteed that all integers between 11 and kk occur at least once among integers aia_{i}.

In the next mm lines roads are described. Each road is described by two integers uu vv (1≤u,v≤n1 \le u, v \le n, u≠vu \ne v) — the towns connected by this road. It is guaranteed that there is no more than one road between every two towns. It is guaranteed that you can go from any town to any other town via roads.

输入的第一行包含 44 个整数 nn、mm、kk、ss(1≤n≤1051 \le n \le 10^{5},0≤m≤1050 \le m \le 10^{5},1≤s≤k≤min⁡(n,100)1 \le s \le k \le \min(n, 100)),分别表示城镇数量、道路数量、商品种类总数、举办集市所需的不同商品种类数。

接下来一行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤k1 \le a_{i} \le k),其中 aia_i 表示第 ii 个城镇所生产商品的种类。保证在所有 aia_i 中,11 到 kk 之间的每个整数至少出现一次。

接下来 mm 行描述道路。每条道路由两个整数 uu、vv(1≤u,v≤n1 \le u, v \le n,u≠vu \ne v)描述,表示连接城镇 uu 和 vv 的一条道路。保证任意两个城镇之间至多只有一条道路。保证通过道路可以从任意一个城镇到达任意其他城镇。

输出格式

Print nn numbers, the ii-th of them is the minimum number of coins you need to spend on travel expenses to hold a fair in town ii. Separate numbers with spaces.

输出 nn 个数字,其中第 ii 个数字表示在第 ii 个城镇举办集市所需支付的旅行费用的最少硬币数。各数字之间用空格分隔。

输入输出样例

  • 输入#1

    5 5 4 3
    1 2 4 3 2
    1 2
    2 3
    3 4
    4 1
    4 5

    输出#1

    2 2 2 2 3
  • 输入#2

    7 6 3 2
    1 2 3 3 2 2 1
    1 2
    2 3
    3 4
    2 5
    5 6
    6 7

    输出#2

    1 1 1 2 2 1 1

说明/提示

Let's look at the first sample.

To hold a fair in town 11 you can bring goods from towns 11 (00 coins), 22 (11 coin) and 44 (11 coin). Total numbers of coins is 22.

Town 22: Goods from towns 22 (00), 11 (11), 33 (11). Sum equals 22.

Town 33: Goods from towns 33 (00), 22 (11), 44 (11). Sum equals 22.

Town 44: Goods from towns 44 (00), 11 (11), 55 (11). Sum equals 22.

Town 55: Goods from towns 55 (00), 44 (11), 33 (22). Sum equals 33.

我们来看第一个样例。

在城镇 11 举办集市,你可以从城镇 11(花费 00 枚硬币)、城镇 22(花费 11 枚硬币)和城镇 44(花费 11 枚硬币)运来货物。总花费为 22 枚硬币。

城镇 22:货物来自城镇 22(花费 00 枚)、城镇 11(花费 11 枚)、城镇 33(花费 11 枚)。总和为 22。

城镇 33:货物来自城镇 33(花费 00 枚)、城镇 22(花费 11 枚)、城镇 44(花费 11 枚)。总和为 22。

城镇 44:货物来自城镇 44(花费 00 枚)、城镇 11(花费 11 枚)、城镇 55(花费 11 枚)。总和为 22。

城镇 55:货物来自城镇 55(花费 00 枚)、城镇 44(花费 11 枚)、城镇 33(花费 22 枚)。总和为 33。

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

首页