Submission details
Task:Course Schedule
Sender:aalto26fh_005
Submission time:2026-10-06 18:41:55 +0300
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#10.04 sdetails
#20.04 sdetails
#30.04 sdetails
#40.04 sdetails
#50.04 sdetails
#60.04 sdetails
#70.04 sdetails
#80.04 sdetails
#90.04 sdetails
#100.04 sdetails
#110.04 sdetails
#120.04 sdetails
#130.04 sdetails
#140.04 sdetails
#150.04 sdetails
#160.04 sdetails
#170.04 sdetails

Code

from collections import deque, defaultdict

def order(n, req):
  adj = defaultdict(list)
  in_deg = [0] * (n + 1)

  for a, b in req:
    adj[a].append(b)
    in_deg[b] += 1

  queue = deque()
  for i in range(1, n + 1):
    if in_deg[i] == 0:
      queue.append(i)

  order = []
  while queue:
    curr = queue.popleft()
    order.append(curr)

    for adjacent in adj[curr]:
      in_deg[adjacent] -= 1
      if in_deg[adjacent] == 0:
        queue.append(adjacent)

  if len(order) == n:
    return " ".join(map(str, order))
  else:
    return "IMPOSSIBLE"

Test details

Test 1

Verdict:

input
10 20
5 2
2 4
8 9
6 4
...

correct output
5 7 10 2 1 8 3 9 6 4 

user output
(empty)

Test 2

Verdict:

input
10 20
2 7
1 10
9 5
9 7
...

correct output
1 8 3 6 10 2 9 4 5 7 

user output
(empty)

Test 3

Verdict:

input
10 20
8 5
2 3
10 1
9 1
...

correct output
4 6 7 9 10 2 8 3 1 5 

user output
(empty)

Test 4

Verdict:

input
10 20
5 10
10 3
9 10
6 2
...

correct output
7 8 6 4 2 1 5 9 10 3 

user output
(empty)

Test 5

Verdict:

input
10 20
2 9
4 8
9 1
10 6
...

correct output
IMPOSSIBLE

user output
(empty)

Test 6

Verdict:

input
100000 200000
78359 8853
18190 30703
11401 30087
34627 11535
...

correct output
2 3 8 9 16 18 21 22 27 34 36 4...

user output
(empty)

Test 7

Verdict:

input
100000 200000
32395 2098
67067 31866
31867 67167
78488 33397
...

correct output
9 11 13 16 22 35 37 38 40 44 5...

user output
(empty)

Test 8

Verdict:

input
100000 200000
19035 36947
13730 46121
99449 77790
15626 11731
...

correct output
1 7 15 17 18 34 38 41 48 49 51...

user output
(empty)

Test 9

Verdict:

input
100000 200000
14188 9709
46541 20871
32203 88809
99879 54779
...

correct output
6 10 11 16 17 19 21 22 23 28 3...

user output
(empty)

Test 10

Verdict:

input
100000 200000
41882 61162
28138 18053
74649 74863
69760 74508
...

correct output
IMPOSSIBLE

user output
(empty)

Test 11

Verdict:

input
100000 199998
1 100000
1 100000
2 100000
2 100000
...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Test 12

Verdict:

input
2 2
1 2
2 1

correct output
IMPOSSIBLE

user output
(empty)

Test 13

Verdict:

input
6 6
1 2
2 3
4 3
4 5
...

correct output
IMPOSSIBLE

user output
(empty)

Test 14

Verdict:

input
99999 149997
1 3
3 5
5 7
7 9
...

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Test 15

Verdict:

input
100000 149998
2 1
3 2
4 3
5 4
...

correct output
100000 99999 99998 99997 99996...

user output
(empty)

Test 16

Verdict:

input
6 6
1 2
1 3
2 4
3 5
...

correct output
IMPOSSIBLE

user output
(empty)

Test 17

Verdict:

input
100000 200000
1 1
1 1
2 2
2 2
...

correct output
IMPOSSIBLE

user output
(empty)