Logo
(追記) (追記ここまで)

32459번 - Kingdom’s Development Plan 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB110886287.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:

  • $n,ドル the number of projects numbered from 1ドル$ to $n$.
  • $m,ドル the number of prerequisite relationships between these projects.
  • A list of $m$ pairs, where each pair $(a, b)$ indicates that project $a$ must be completed before project $b$ can start.

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.

제한

  • 1ドル ≤ n ≤ 10^5$
  • 0ドル ≤ m ≤ 2 \times 10^5$
  • $a, b \in \{1, 2,\dots ,n\}$
  • $a \ne b$
  • No duplicate pairs are given.

예제 입력 1

5 5
1 2
2 3
2 4
2 5
3 4

예제 출력 1

1 2 3 4 5

예제 입력 2

5 4
1 2
2 3
3 1
5 4

예제 출력 2

IMPOSSIBLE

힌트

출처

ICPC > Regionals > Asia Pacific > Taiwan > Taiwan Online Programming Contest > TOPC 2024 K번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /