logo AlgoBeat OnlineJudge
登录 注册

#215980. [TOPC 2024] Kingdom' s Development Plan

内存限制:512 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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:

  • , the number of projects numbered from to .
  • , the number of prerequisite relationships between these projects.
  • A list of pairs, where each pair indicates that project must be completed before project 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 and — the number of projects and the number of prerequisite relationships. The next lines each contain two integers and — a prerequisite pair indicating that project must be completed before project .

输出格式

If it is not possible, output “IMPOSSIBLE”. If it is possible to complete all projects, output a single line with 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

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

数据范围与提示

  • No duplicate pairs are given.