CF1615H.Reindeer Games

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn reindeer at the North Pole, all battling for the highest spot on the "Top Reindeer" leaderboard on the front page of CodeNorses (a popular competitive reindeer gaming website). Interestingly, the "Top Reindeer" title is just a measure of upvotes and has nothing to do with their skill level in the reindeer games, but they still give it the utmost importance.

Currently, the ii-th reindeer has a score of aia_i. You would like to influence the leaderboard with some operations. In an operation, you can choose a reindeer, and either increase or decrease his score by 11 unit. Negative scores are allowed.

You have mm requirements for the resulting scores. Each requirement is given by an ordered pair (u,v)(u, v), meaning that after all operations, the score of reindeer uu must be less than or equal to the score of reindeer vv.

Your task is to perform the minimum number of operations so that all requirements will be satisfied.

在北极有 nn 只驯鹿,它们都在争夺 CodeNorses(一个广受欢迎的驯鹿竞技游戏网站)首页“顶尖驯鹿”排行榜上的最高排名。有趣的是,“顶尖驯鹿”头衔仅由点赞数决定,与其在驯鹿游戏中的实际技能水平毫无关系,但它们依然对此极为重视。

目前,第 ii 只驯鹿的得分为 aia_i。你希望通过若干操作来影响该排行榜。每次操作中,你可以任选一只驯鹿,并将其得分增加或减少 11 单位。允许出现负分。

你对最终得分有 mm 项约束条件。每项约束由一个有序对 (u,v)(u, v) 给出,表示在所有操作完成后,驯鹿 uu 的得分必须小于等于驯鹿 vv 的得分。

你的任务是执行最少次数的操作,使得所有约束条件均被满足。

输入格式

The first line contains two integers nn and mm (2≤n≤10002\le n\le 1000; 1≤m≤10001\le m\le 1000) — the number of reindeer and requirements, respectively.

The second line contains nn integers a1,…,ana_1,\ldots, a_n (1≤ai≤1091\le a_i\le 10^9), where aia_i is the current score of reindeer ii.

The next mm lines describe the requirements.

The ii-th of these lines contains two integers uiu_i and viv_i (1≤ui,vi≤n1\le u_i, v_i\le n; ui≠viu_i\ne v_i) — the two reindeer of the ii-th requirement.

第一行包含两个整数 nn 和 mm(2≤n≤10002\le n\le 1000;1≤m≤10001\le m\le 1000),分别表示驯鹿的数量和要求的数量。

第二行包含 nn 个整数 a1,…,ana_1,\ldots, a_n(1≤ai≤1091\le a_i\le 10^9),其中 aia_i 表示第 ii 只驯鹿当前的得分。

接下来的 mm 行描述各项要求。

其中第 ii 行包含两个整数 uiu_i 和 viv_i(1≤ui,vi≤n1\le u_i, v_i\le n;ui≠viu_i\ne v_i),表示第 ii 项要求所涉及的两只驯鹿。

输出格式

Print nn integers b1,…,bnb_1,\ldots, b_n (−1015≤bi≤1015-10^{15}\le b_i\le 10^{15}), where bib_i is the score of the ii-th reindeer after all operations.

If there are multiple solutions achieving the minimum number of operations, you may output any.

We can prove that there is always an optimal solution such that ∣bi∣≤1015|b_i|\le 10^{15} for all ii.

输出 nn 个整数 b1,…,bnb_1,\ldots, b_n(满足 −1015≤bi≤1015-10^{15}\le b_i\le 10^{15}),其中 bib_i 表示第 ii 只驯鹿在所有操作完成后的得分。

若存在多种方案均能达到最少操作次数,你可以输出其中任意一种。

我们可以证明:总存在一种最优解,使得对所有 ii 均有 ∣bi∣≤1015|b_i|\le 10^{15}。

输入输出样例

  • 输入#1

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

    输出#1

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

    4 6
    6 5 8 2
    3 1
    4 1
    3 2
    1 2
    2 3
    3 1

    输出#2

    6 6 6 2
  • 输入#3

    10 18
    214 204 195 182 180 176 176 172 169 167
    1 2
    3 2
    4 2
    5 2
    6 2
    7 2
    8 2
    9 2
    10 2
    6 1
    6 2
    6 3
    6 4
    6 5
    6 7
    6 8
    6 9
    6 10

    输出#3

    204 204 195 182 180 167 176 172 169 167

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

首页