| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 110 | 88 | 62 | 87.324% |
The Kingdom of Topcaria is planning a series of developmental projects to enhance its infrastructure. Each project has specific prerequisites that must be completed before the project can start. The Ministry of Development has asked you to help determine a feasible order in which all the projects can be completed.
You are given:
Your task is to determine an order in which all the projects can be completed. If it is impossible to complete all projects due to a cyclic dependency, output “IMPOSSIBLE”. If there are multiple valid orders, please output any the lexicographically smallest one.
The first line contains two integers $n$ and $m$ — the number of projects and the number of prerequisite relationships. The next $m$ lines each contain two integers $a$ and $b$ — a prerequisite pair indicating that project $a$ must be completed before project $b$.
If it is not possible, output “IMPOSSIBLE”. If it is possible to complete all projects, output a single line with $n$ integers — a valid order of project completions. If there are multiple possible orders, output the lexicographically smallest one. An order is lexicographically smaller than another order if at the first position where they differ, the project number on the first order is smaller than the number on the second order.
5 5 1 2 2 3 2 4 2 5 3 4
1 2 3 4 5
5 4 1 2 2 3 3 1 5 4
IMPOSSIBLE
ICPC > Regionals > Asia Pacific > Taiwan > Taiwan Online Programming Contest > TOPC 2024 K번