#BF0000016. Quan sát Vụ Nổ Lớn tức thì (Instant View of Big Bang)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Quan sát Vụ Nổ Lớn tức thì (Instant View of Big Bang)
Instant View of Big Bang
Source: LightOJ
Version: Phuoc Hung OJ Extended
Problem Statement
There are star systems numbered through and one-way wormholes. Traversing wormhole changes the time by integer , possibly negative. A scientist may choose any starting system. Find every starting system from which she can reach some directed cycle of negative total time displacement and repeat it indefinitely.
Input
The first line contains , followed by lines . There are no self-loops or repeated edges in the same direction.
Output
Print all valid starting star-system indices in increasing order, separated by spaces; if none exist, print impossible.
Subtasks
-
Subtask 1 (20 points): ; ; ; no self-loops or duplicate directed pairs.
-
Subtask 2 (30 points): ; ; ; no self-loops or duplicate directed pairs.
-
Subtask 3 (50 points): ; ; ; no self-loops or duplicate directed pairs.
Examples
Input
4 3
0 1 2
1 2 -4
2 1 1
Output
0 1 2
Explanation
The cycle has total time . Vertices can reach it; vertex cannot.