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

#FW0000124. Tấn công điểm số (Score Attack)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tấn công điểm số (Score Attack)

Score Attack

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Given a directed graph with integer edge scores, possibly negative, start at vertex 11 with score zero. Each edge traversal adds its weight to the score. You may end only at vertex nn, which is guaranteed reachable from 11. Find the maximum final score, or print exactly inf if a reachable positive cycle can be used indefinitely and still allows reaching nn.

Input

First line n,mn,m; then mm directed edges u,v,wu,v,w. Vertices are 11-indexed; no self-loops or duplicated ordered edge pairs.

Output

Print the maximum score or inf.

Subtasks

  • Subtask 1 (40 points): 2≤n≤82\le n\le 8, 1≤m≤141\le m\le 14, ∣w∣≤30|w|\le 30, tồn tại đường từ 11 tới nn. All input conditions remain in force.

  • Subtask 2 (60 points): 2≤n≤10002\le n\le 1000, 1≤m≤min⁡(n(n−1),2000)1\le m\le\min(n(n-1),2000), ∣w∣≤109|w|\le 10^9, tồn tại đường từ 11 tới nn. All input conditions remain in force.

Examples

Input

3 3
1 2 4
2 3 3
1 3 5

Output

7

Explanation

The route 1->2->3 scores 4+3=7, more than the direct edge scoring 5.