SAC '22 Code Challenge 5 Junior P4 - Course Requirements

View as PDF

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 N courses.

However, each course has Ci prerequisites, and Max cannot schedule properly.

Can you tell Max the order to take his courses to satisfy the prerequisites?

Constraints

1N2×105

0Ci<N

i=1NCimin(N(N1)2,2×105)

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%]

1N10

Subtask 2 [60%]

No additional constraints.

Input Specification

The first line will contain an integer, N, the number of courses in the schedule.

The next N lines will contain an integer, Ci, and Ci integers, representing the number of prerequisites for the ith course and its prerequisites.

Output Specification

Output any valid permutation of the N courses, where each course is not missing a prerequisite when it is taken.

Sample Input

Copy
5
0
0
3 1 2 5
3 1 2 3
1 2

Sample Output

Copy
1 2 5 3 4

Comments

There are no comments at the moment.