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

#BF0000026. Trì hoãn đầy cảm hứng (Inspired Procrastination)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Trì hoãn đầy cảm hứng (Inspired Procrastination)

Inspired Procrastination

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Life is modeled as NN decision points numbered 11 through NN. You start at point 11. Each of MM directed choices moves from AA to BB and adds signed procrastination factor FF. You may revisit points and may stop anywhere, at any time. Find the maximum possible accumulated procrastination, or print Unlimited! if it can be increased without bound.

Input

The first line contains N,MN,M. Each following line has A,B,FA,B,F, where A≠BA\ne B and no ordered pair is repeated.

Output

Print Unlimited! if unbounded, otherwise the maximum accumulated factor (at least 00 because stopping immediately is permitted).

Subtasks

  • Subtask 1 (20 points): 1≤N≤121\le N\le12; 0≤M≤600\le M\le60; −100≤w≤100-100\le w\le100; no self-loops or repeated directed pairs.

  • Subtask 2 (30 points): 1≤N≤501\le N\le50; 0≤M≤5000\le M\le500; −1000≤w≤1000-1000\le w\le1000; no self-loops or repeated directed pairs.

  • Subtask 3 (50 points): 1≤N≤1001\le N\le100; 0≤M≤99000\le M\le9900; −1000≤w≤1000-1000\le w\le1000; no self-loops or repeated directed pairs.

Examples

Input

3 3
1 2 10
2 3 20
3 1 -30

Output

30

Explanation

The walk 1→2→31\to2\to3 yields 3030. The cycle returning to vertex 11 has weight 10+20−30=010+20-30=0, so it cannot increase the optimum.