CF1765H.Hospital Queue
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n people (numbered from 1 to n ) signed up for a doctor's appointment. The doctor has to choose in which order he will appoint these people. The i -th patient should be appointed among the first pi people. There are also m restrictions of the following format: the i -th restriction is denoted by two integers (ai,bi) and means that the patient with the index ai should be appointed earlier than the patient with the index bi .
For example, if n=4 , p=[2,3,2,4] , m=1 , a=[3] and b=[1] , then the only order of appointment of patients that does not violate the restrictions is [3,1,2,4] . For n=3 , p=[3,3,3] , m=0 , a=[] and b=[] , any order of appointment is valid.
For each patient, calculate the minimum position in the order that they can have among all possible orderings that don't violate the restrictions.
输入格式
The first line contains two integers n and m ( 1≤n≤2000 ; 0≤m≤2000 ).
The second line contains n integers p1,p2,…,pn ( 1≤pi≤n ).
Then m lines follow. The i -th of them contains two integers ai and bi ( 1≤ai,bi≤n ; ai=bi ). All pairs of (ai,bi) are distinct (i. e. if i=j , then either ai=aj , bi=bj , or both).
Additional constraint on the input: there is at least one valid order of patients.
输出格式
Print n integers, where i -th integer is equal to the minimum position of i -th patient in the order, among all valid orders. Positions in the order are numbered from 1 to n .
输入输出样例
输入#1
4 1 2 3 2 4 3 1
输出#1
2 3 1 4
输入#2
3 0 3 3 3
输出#2
1 1 1
输入#3
5 3 4 3 3 2 5 3 1 1 5 4 2
输出#3
4 2 1 1 5
说明/提示
In the first example, [3,1,2,4] the only one valid order, so the minimum position of each patient is equal to their position in this order.
In the second example, any order is valid, so any patient can be appointed first.
In the third example, there are three valid orders: [4,2,3,1,5] , [3,4,2,1,5] and [4,3,2,1,5] .