CF400D.Dima and Bacteria

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Dima took up the biology of bacteria, as a result of his experiments, he invented k types of bacteria. Overall, there are n bacteria at his laboratory right now, and the number of bacteria of type i equals c__i. For convenience, we will assume that all the bacteria are numbered from 1 to n. The bacteria of type c__i are numbered from to .

With the help of special equipment Dima can move energy from some bacteria into some other one. Of course, the use of such equipment is not free. Dima knows m ways to move energy from some bacteria to another one. The way with number i can be described with integers u__i, v__i and x__i mean that this way allows moving energy from bacteria with number u__i to bacteria with number v__i or vice versa for x__i dollars.

Dima's Chef (Inna) calls the type-distribution correct if there is a way (may be non-direct) to move energy from any bacteria of the particular type to any other bacteria of the same type (between any two bacteria of the same type) for zero cost.

As for correct type-distribution the cost of moving the energy depends only on the types of bacteria help Inna to determine is the type-distribution correct? If it is, print the matrix d with size k × k. Cell d[i][j] of this matrix must be equal to the minimal possible cost of energy-moving from bacteria with type i to bacteria with type j.

季马开始研究细菌生物学,通过实验,他发明了 kk 种细菌。目前他的实验室中共有 nn 个细菌,其中第 ii 种细菌的数量为 cic_i。为方便起见,我们假设所有细菌编号为 11 到 nn。第 ii 种细菌的编号范围是从 到 。

借助特殊设备,季马可将能量从某些细菌转移到另一些细菌。当然,使用该设备并非免费。季马已知 mm 种能量转移方式。第 ii 种方式由整数 uiu_i、viv_i 和 xix_i 描述,表示可通过花费 xix_i 美元,将能量在编号为 uiu_i 的细菌与编号为 viv_i 的细菌之间双向转移。

季马的厨师(因娜)称一种“类型分布”是正确的,当且仅当:对于任意特定类型的任意两个细菌,均存在一条(未必直接)路径,使得能量可在它们之间以 零成本 进行转移。

对于正确的类型分布,能量转移的成本仅取决于细菌的类型。请帮助因娜判断当前类型分布是否正确?若正确,请输出一个大小为 k×kk \times k 的矩阵 dd;其中矩阵元素 d[i][j]d[i][j] 表示从任意一个第 ii 类细菌向任意一个第 jj 类细菌转移能量所需的最小可能成本。

输入格式

The first line contains three integers n, m, k (1 ≤ n ≤ 105; 0 ≤ m ≤ 105; 1 ≤ k ≤ 500). The next line contains k integers _c_1, _c_2, ..., c__k (1 ≤ c__i ≤ n). Each of the next m lines contains three integers u__i, v__i, x__i (1 ≤ u__i, v__i ≤ 105; 0 ≤ x__i ≤ 104). It is guaranteed that .

第一行包含三个整数 nn、mm、kk(1≤n≤1051 \leq n \leq 10^5;0≤m≤1050 \leq m \leq 10^5;1≤k≤5001 \leq k \leq 500)。
第二行包含 kk 个整数 c1,c2,…,ckc_1, c_2, \dots, c_k(1≤ci≤n1 \leq c_i \leq n)。
接下来的 mm 行,每行包含三个整数 ui,vi,xiu_i, v_i, x_i(1≤ui,vi≤1051 \leq u_i, v_i \leq 10^5;0≤xi≤1040 \leq x_i \leq 10^4)。
保证满足条件:

输出格式

If Dima's type-distribution is correct, print string «Yes», and then k lines: in the i-th line print integers d[i][1], d[i][2], ..., d[i][k] (d[i][i] = 0). If there is no way to move energy from bacteria i to bacteria j appropriate d[i][j] must equal to -1. If the type-distribution isn't correct print «No».

如果迪马的类型分布是正确的,则输出字符串「Yes」,然后输出 k 行:第 i 行输出整数 d[i][1], d[i][2], ..., d[i][k](其中 d[i][i] = 0)。若不存在从细菌 i 向细菌 j 传递能量的路径,则对应的 d[i][j] 必须为 -1。若该类型分布不正确,则输出「No」。

输入输出样例

  • 输入#1

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

    输出#1

    Yes
    0 2
    2 0
  • 输入#2

    3 1 2
    2 1
    1 2 0

    输出#2

    Yes
    0 -1
    -1 0
  • 输入#3

    3 2 2
    2 1
    1 2 0
    2 3 1

    输出#3

    Yes
    0 1
    1 0
  • 输入#4

    3 0 2
    1 2

    输出#4

    No

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

首页