Submit solution
Points:
7 (partial)
Time limit:
1.0s
Java
1.5s
Memory limit:
256M
Author:
Problem type
Since Max is heading off to university, he needs to create a course schedule for courses.
However, each course has prerequisites, and Max cannot schedule properly.
Can you tell Max the order to take his courses to satisfy the prerequisites?
Constraints
It is always possible to generate a course schedule that does not conflict (i.e., it is possible to take every course without missing a prerequisite).
Subtask 1 [40%]
Subtask 2 [60%]
No additional constraints.
Input Specification
The first line will contain an integer, , the number of courses in the schedule.
The next lines will contain an integer, , and integers, representing the number of prerequisites for the course and its prerequisites.
Output Specification
Output any valid permutation of the courses, where each course is not missing a prerequisite when it is taken.
Sample Input
5
0
0
3 1 2 5
3 1 2 3
1 2
Sample Output
1 2 5 3 4
Comments