CF883B.Berland Army

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are n military men in the Berland army. Some of them have given orders to other military men by now. Given m pairs (x__i, y__i), meaning that the military man x__i gave the i-th order to another military man y__i.

It is time for reform! The Berland Ministry of Defence plans to introduce ranks in the Berland army. Each military man should be assigned a rank — integer number between 1 and k, inclusive. Some of them have been already assigned a rank, but the rest of them should get a rank soon.

Help the ministry to assign ranks to the rest of the army so that:

  • for each of m orders it is true that the rank of a person giving the order (military man x__i) is strictly greater than the rank of a person receiving the order (military man y__i);
  • for each rank from 1 to k there is at least one military man with this rank.

贝兰德军队中有 nn 名军人。目前,其中一些人已经向其他军人下达了命令。给定 mm 对 (xi,yi)(x_i, y_i),表示第 ii 条命令由军人 xix_i 下达给另一名军人 yiy_i。

现在是改革的时候了!贝兰德国防部计划在贝兰德军队中引入军衔制度。每名军人应被授予一个军衔——即介于 11 到 kk(含)之间的整数。其中部分军人的军衔已预先确定,而其余军人的军衔尚待分配。

请帮助国防部为其余军人分配军衔,使得:

  • 对于全部 mm 条命令,下令者(军人 xix_i)的军衔严格大于受令者(军人 yiy_i)的军衔;
  • 对于从 11 到 kk 的每一个军衔值,至少有一名军人拥有该军衔。

输入格式

The first line contains three integers n, m and k (1 ≤ n ≤ 2·105, 0 ≤ m ≤ 2·105, 1 ≤ k ≤ 2·105) — number of military men in the Berland army, number of orders and number of ranks.

The second line contains n integers _r_1, _r_2, ..., r__n, where r__i > 0 (in this case 1 ≤ r__i ≤ k) means that the i-th military man has been already assigned the rank r__i; r__i = 0 means the i-th military man doesn't have a rank yet.

The following m lines contain orders one per line. Each order is described with a line containing two integers x__i, y__i (1 ≤ x__i, y__i ≤ n, x__i ≠ y__i). This line means that the i-th order was given by the military man x__i to the military man y__i. For each pair (x, y) of military men there could be several orders from x to y.

第一行包含三个整数 nn、mm 和 kk(1 ≤ n ≤ 2⋅1051 \leq n \leq 2\cdot10^5,0 ≤ m ≤ 2⋅1050 \leq m \leq 2\cdot10^5,1 ≤ k ≤ 2⋅1051 \leq k \leq 2\cdot10^5)——分别表示 Berland 军队中军人的数量、命令的数量以及军衔的种类数。

第二行包含 nn 个整数 r1, r2, ..., rnr_1,\,r_2,\,...,\,r_n,其中:若 ri>0r_i > 0(此时满足 1≤ri≤k1 \leq r_i \leq k),表示第 ii 位军人已被授予军衔 rir_i;若 ri=0r_i = 0,表示第 ii 位军人尚未被授予任何军衔。

接下来的 mm 行每行描述一条命令。每条命令由两个整数 xix_i、yiy_i(1 ≤ xi, yi ≤ n1 \leq x_i,\,y_i \leq n,且 xi ≠ yix_i \neq y_i)组成。该行表示第 ii 条命令由军人 xix_i 下达给军人 yiy_i。对于任意一对军人 (x, y)(x,\,y),可能存在多条从 xx 到 yy 的命令。

输出格式

Print n integers, where the i-th number is the rank of the i-th military man. If there are many solutions, print any of them.

If there is no solution, print the only number -1.

输出 n 个整数,其中第 i 个数表示第 i 位军人的排名。若存在多种解,输出任意一种即可。

若无解,则仅输出数字 -1。

输入输出样例

  • 输入#1

    5 3 3
    0 3 0 0 2
    2 4
    3 4
    3 5

    输出#1

    1 3 3 2 2
  • 输入#2

    7 6 5
    0 4 5 4 1 0 0
    6 1
    3 6
    3 1
    7 5
    7 1
    7 4

    输出#2

    2 4 5 4 1 3 5
  • 输入#3

    2 2 2
    2 1
    1 2
    2 1

    输出#3

    -1

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

首页