아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Mistake

시간 제한3초메모리 제한256 MB

요약
뒤섞인 k개의 위상 정렬 로그를 각각 의존 관계를 만족하는 k개의 실행 순서로 나눈다.
난이도

보통10점 중 7점

유형
위상 정렬, 그리디, 큐
정답자
아직 제출이 없습니다

문제

As an apprentice algorithms enthusiast, it is not a great surprise that Mike struggles to cope with overly complex systems. Unfortunately, this turned out to be a big problem in the company he is currently interning.

Mike’s assigned project involves tinkering with the company’s Intelligent Cluster for Parallel Computation. This is just a fancy name; in reality, the system is just a simple job scheduler, handling a total of nn jobs. Some jobs might depend on successful execution of other jobs before being able to be executed. There are mm such dependencies in total.

It is guaranteed that there are no (direct or indirect) circular dependencies between jobs.

When a run is started, the systems intelligently picks an order to execute these jobs so that all the dependencies are met (the order may change between different runs). After picking a valid ordering, it starts executing each of the nn jobs in that order. When the system starts executing a job, it prints the id of the job to a log file.

Unfortunately, today was Mike’s first day interning at the company and he wasn’t very cautious. Consequently, he accidentally ran the system kk times in parallel. The system started erratically launching jobs and printing to the log file. Now the log file contains n⋅kn \cdot k ids of all the jobs that were executed. The job ids from the same run have been printed in the order they were executed, but the outputs from different runs may appear interweaved arbitrarily.

Your task is to figure out which jobs were executed in each of the kk runs from the information inside the log file.

입력

The first line of the input will contain three integers nn, kk, mm (1≤n,k≤500,0001 \le n, k \le 500\\,000, 0≤m≤250,0000 \le m \le 250\\,000, n⋅k≤500,000n \cdot k \le 500\\,000), the number of jobs in the system, the number of runs Mike had triggered, and the number of dependencies.

The following mm lines will contain a pair a_ia\_i, b_ib\_i (1≤a_i,b_i≤n1 \le a\_i , b\_i \le n, a_i≠b_ia\_i \ne b\_i, for all 1≤i≤ m1 \le i \le m) describing a dependency of kind: “job a_ia\_i must be executed before job b_ib\_i”.

Finally, the last line of the input contains n⋅kn \cdot k integers c_ic\_i (1≤c_i≤n1 \le c\_i \le n, for all 1≤i≤n⋅ k1 \le i \le n \cdot k), the job ids that have been printed in the log file, in order.

출력

Output a single line consisting of n⋅kn \cdot k integers r_ir\_i (1≤r_i≤k1 \le r\_i \le k, for all 1≤i≤n⋅k1 \le i \le n \cdot k), the run id corresponding to each of the jobs in the log file. More specifically, r_ir\_i should be the run id corresponding to the ii-th job, as it appears in the log file.

If multiple solutions are possible, any one is accepted. It is guaranteed that the input data is valid and that a solution always exists.

예제1

  1. 예제 1

    입력
    3 3 2
    1 2
    1 3
    1 1 2 3 3 2 1 2 3
    
    예상 출력
    1 2 2 1 2 1 3 3 3