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

#BF0000020. 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

You are given a directed graph with NN vertices and MM edges. Moving along an edge adds its possibly negative score cc. Start at vertex 11 with score zero and finish only at vertex NN, which is reachable. Edges may be reused. Find the maximum finishing score, or print inf if it is unbounded.

Input

The first line contains N,MN,M, then MM lines a,b,ca,b,c. Self-loops and repeated ordered edge pairs are absent.

Output

Print inf if unbounded; otherwise print the maximum score.

Subtasks

  • Subtask 1 (20 points): 2≤N≤152\le N\le15; 1≤M≤501\le M\le50; −100≤w≤100-100\le w\le100; no self-loops or duplicate directed pairs; target reachable.

  • Subtask 2 (30 points): 2≤N≤1002\le N\le100; 1≤M≤4001\le M\le400; −1000000≤w≤1000000-1000000\le w\le1000000; no self-loops or duplicate directed pairs; target reachable.

  • Subtask 3 (50 points): 2≤N≤10002\le N\le1000; 1≤M≤20001\le M\le2000; −1000000000≤w≤1000000000-1000000000\le w\le1000000000; no self-loops or duplicate directed pairs; target reachable.

Examples

Input

3 3
1 2 4
2 3 3
1 3 5

Output

7

Explanation

The route 1→2→31\to2\to3 gains 4+3=74+3=7, compared with 55 for the direct edge.