CF1361A.Johnny and Contribution
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Today Johnny wants to increase his contribution. His plan assumes writing n blogs. One blog covers one topic, but one topic can be covered by many blogs. Moreover, some blogs have references to each other. Each pair of blogs that are connected by a reference has to cover different topics because otherwise, the readers can notice that they are split just for more contribution. Set of blogs and bidirectional references between some pairs of them is called blogs network.
There are n different topics, numbered from 1 to n sorted by Johnny's knowledge. The structure of the blogs network is already prepared. Now Johnny has to write the blogs in some order. He is lazy, so each time before writing a blog, he looks at it's already written neighbors (the blogs referenced to current one) and chooses the topic with the smallest number which is not covered by neighbors. It's easy to see that this strategy will always allow him to choose a topic because there are at most n−1 neighbors.
For example, if already written neighbors of the current blog have topics number 1, 3, 1, 5, and 2, Johnny will choose the topic number 4 for the current blog, because topics number 1, 2 and 3 are already covered by neighbors and topic number 4 isn't covered.
As a good friend, you have done some research and predicted the best topic for each blog. Can you tell Johnny, in which order he has to write the blogs, so that his strategy produces the topic assignment chosen by you?
今天,Johnny 想要提升自己的贡献值。他的计划是撰写 n 篇博客。每篇博客覆盖一个主题,但一个主题可以被多篇博客覆盖。此外,某些博客之间存在相互引用关系。对于任意一对通过引用相互关联的博客,它们必须覆盖不同的主题;否则,读者会察觉这些博客只是被人为拆分以刷贡献值。博客集合以及其中某些博客对之间的双向引用关系,共同构成一个博客网络。
共有 n 个互不相同的话题,编号为 1 到 n,按 Johnny 对其的熟悉程度升序排列。博客网络的结构已经预先确定。现在 Johnny 需要以某种顺序撰写这些博客。他比较懒惰,因此每次在撰写一篇博客前,都会查看它已撰写完成的邻居博客(即那些引用了当前这篇博客的博客),并从中选择编号最小、且尚未被这些邻居博客所覆盖的主题。容易看出,该策略总能成功选出一个主题,因为任一博客最多只有 n−1 个邻居。
例如,若当前博客的已撰写邻居博客所覆盖的主题编号分别为 1、3、1、5 和 2,则 Johnny 将为当前博客选择主题编号 4,因为主题 1、2、3 已被邻居覆盖,而主题 4 尚未被覆盖。
作为一位好朋友,你已提前开展研究,并为每篇博客预测出了最优主题。那么,你能告诉 Johnny:他应以怎样的顺序撰写博客,才能使其上述贪心策略最终生成你所选定的主题分配方案?
输入格式
The first line contains two integers n (1≤n≤5⋅105) and m (0≤m≤5⋅105) — the number of blogs and references, respectively.
Each of the following m lines contains two integers a and b (a=b; 1≤a,b≤n), which mean that there is a reference between blogs a and b. It's guaranteed that the graph doesn't contain multiple edges.
The last line contains n integers t1,t2,…,tn, i-th of them denotes desired topic number of the i-th blog (1≤ti≤n).
第一行包含两个整数 n(1≤n≤5⋅105)和 m(0≤m≤5⋅105),分别表示博客的数量和引用关系的数量。
接下来的 m 行,每行包含两个整数 a 和 b(a=b;1≤a,b≤n),表示博客 a 与博客 b 之间存在一条引用关系。保证图中不存在重边。
最后一行包含 n 个整数 t1,t2,…,tn,其中第 i 个数 ti 表示第 i 个博客所期望的主题编号(1≤ti≤n)。
输出格式
If the solution does not exist, then write −1. Otherwise, output n distinct integers p1,p2,…,pn (1≤pi≤n), which describe the numbers of blogs in order which Johnny should write them. If there are multiple answers, print any.
如果解不存在,则输出 −1。否则,输出 n 个互不相同的整数 p1,p2,…,pn(其中 1≤pi≤n),表示 Johnny 应该按此顺序撰写博客的编号。若存在多个答案,输出任意一个即可。
输入输出样例
输入#1
3 3 1 2 2 3 3 1 2 1 3
输出#1
2 1 3
输入#2
3 3 1 2 2 3 3 1 1 1 1
输出#2
-1
输入#3
5 3 1 2 2 3 4 5 2 1 2 2 1
输出#3
2 5 1 3 4
说明/提示
In the first example, Johnny starts with writing blog number 2, there are no already written neighbors yet, so it receives the first topic. Later he writes blog number 1, it has reference to the already written second blog, so it receives the second topic. In the end, he writes blog number 3, it has references to blogs number 1 and 2 so it receives the third topic.
Second example: There does not exist any permutation fulfilling given conditions.
Third example: First Johnny writes blog 2, it receives the topic 1. Then he writes blog 5, it receives the topic 1 too because it doesn't have reference to single already written blog 2. Then he writes blog number 1, it has reference to blog number 2 with topic 1, so it receives the topic 2. Then he writes blog number 3 which has reference to blog 2, so it receives the topic 2. Then he ends with writing blog number 4 which has reference to blog 5 and receives the topic 2.
在第一个例子中,Johnny 首先撰写博客编号 2,此时尚无已撰写的相邻博客,因此它获得第一个主题。随后他撰写博客编号 1,该博客引用了已撰写的第二个博客,因此它获得第二个主题。最后,他撰写博客编号 3,该博客引用了博客编号 1 和 2,因此它获得第三个主题。
第二个例子:不存在满足给定条件的排列。
第三个例子:Johnny 首先撰写博客 2,它获得主题 1。接着他撰写博客 5,由于它并未引用唯一已撰写的博客 2,因此也获得主题 1。然后他撰写博客编号 1,该博客引用了主题为 1 的博客 2,因此它获得主题 2。接着他撰写博客编号 3,该博客引用了博客 2,因此也获得主题 2。最后他撰写博客编号 4,该博客引用了博客 5,因此获得主题 2。
输入解题思路,AI测评打分。不知道怎么写?