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

#BF0000014. Chu trình âm (Negative Cycles)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

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 11 through nn. You start at vertex 11 and wish to reach vertex nn. 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 n,mn,m. Each of the next mm lines contains a,b,ca,b,c denoting an edge a→ba\to b of cost cc.

Output

Print negative infinity if the cost is unbounded below; unreachable if there is no path from 11 to nn; otherwise print the finite minimum.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; 0≤m≤800\le m\le80; −100≤w≤100-100\le w\le100.

  • Subtask 2 (30 points): 1≤n≤801\le n\le80; 0≤m≤10000\le m\le1000; −1000≤w≤1000-1000\le w\le1000.

  • Subtask 3 (50 points): 1≤n≤3001\le n\le300; 0≤m≤100000\le m\le10000; −1000≤w≤1000-1000\le w\le1000.

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 2→3→4→22\to3\to4\to2 has total cost −1-1 and still leads to vertex 55. Repeating it makes the cost arbitrarily small.