LearnPy Hub
← Arena
AdvancedRating 1800

Shortest Paths With Negative Roads

Roads are one-way and some have negative length. Print the shortest distance from city 1 to every city (INF if unreachable). If a negative loop can be reached from city 1, print only NEGATIVE CYCLE.

Input

n and m; then m lines 'u v w'.

Output

n values on one line, or NEGATIVE CYCLE.

Sample 1

Input
4 4
1 2 4
1 3 5
3 2 -2
2 4 3
Output
0 3 5 6

Sample 2

Input
3 3
1 2 1
2 3 -1
3 2 -1
Output
NEGATIVE CYCLE
solution.py
Output appears here
Shortest Paths With Negative Roads · Python Arena problem · LearnPy Hub