#BF0000014. Chu trình âm (Negative Cycles)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chu trình âm (Negative Cycles)
Negative Cycles
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a weighted directed graph with vertices numbered through . You start at vertex and wish to reach vertex . Edges may be traversed repeatedly. Find the smallest possible total edge weight of such a walk. Distinguish a finite optimum, no reachable walk, and walks whose cost can be made arbitrarily negative.
Input
The first line contains . Each of the next lines contains denoting an edge of cost .
Output
Print negative infinity if the cost is unbounded below; unreachable if there is no path from to ; otherwise print the finite minimum.
Subtasks
-
Subtask 1 (20 points): ; ; .
-
Subtask 2 (30 points): ; ; .
-
Subtask 3 (50 points): ; ; .
Examples
Input
5 5
1 2 100
2 3 -1
3 4 10
4 2 -10
3 5 100
Output
negative infinity
Explanation
The reachable cycle has total cost and still leads to vertex . Repeating it makes the cost arbitrarily small.