PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BF0000016. Quan sát Vụ Nổ Lớn tức thì (Instant View of Big Bang)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 nn star systems numbered 00 through n−1n-1 and mm one-way wormholes. Traversing wormhole u→vu\to v changes the time by integer ww, 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 n,mn,m, followed by mm lines u,v,wu,v,w. 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): 1≤n≤201\le n\le20; 0≤m≤900\le m\le90; −100≤w≤100-100\le w\le100; no self-loops or duplicate directed pairs.

  • Subtask 2 (30 points): 1≤n≤801\le n\le80; 0≤m≤5000\le m\le500; −1000≤w≤1000-1000\le w\le1000; no self-loops or duplicate directed pairs.

  • Subtask 3 (50 points): 1≤n≤10001\le n\le1000; 0≤m≤20000\le m\le2000; −1000≤w≤1000-1000\le w\le1000; 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 1→2→11\to2\to1 has total time −3-3. Vertices 0,1,20,1,2 can reach it; vertex 33 cannot.