Problem:
Score : 400 points

Problem Statement

There is a directed graph with N vertices and M edges.
The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i.
We will play the following single-player game using this graph and a piece.

Initially, the piece is placed at vertex 1, and the score of the player is set to 0.
The player can move the piece as follows:

When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i.

The player can end the game only when the piece is placed at vertex N.
The given graph guarantees that it is possible to traverse from vertex 1 to vertex N.

When the player acts optimally to maximize the score at the end of the game, what will the score be?
If it is possible to increase the score indefinitely, print inf.

Constraints

2≤N≤1000

1≤M≤min(N(N-1),2000)

1≤a_i,b_i≤N (1≤i≤M)

a_i≠b_i (1≤i≤M)

a_i≠a_j or b_i≠b_j (1≤i<j≤M)

-10^9≤c_i≤10^9 (1≤i≤M)

c_i is an integer.

In the given graph, there exists a path from vertex 1 to vertex N.

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1 c_1
a_2 b_2 c_2
:
a_M b_M c_M

Output

Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print inf.

Sample Input 1

3 3
1 2 4
2 3 3
1 3 5

Sample Output 1

7

There are two ways to move the piece to vertex N=3:

vertex 1 → vertex 2 → vertex 3 : score 4+3=7

vertex 1 → vertex 3 : score 5

Thus, the maximum possible score at the end of the game is 7.

Sample Input 2

2 2
1 2 1
2 1 1

Sample Output 2

inf

It is possible to increase the score indefinitely by alternating between vertex 1 and 2.

Sample Input 3

6 5
1 2 -1000000000
2 3 -1000000000
3 4 -1000000000
4 5 -1000000000
5 6 -1000000000

Sample Output 3

-5000000000

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Program
{
    public class ABC061D
    {
        static class Console_
        {
            private static Queue<string> param = new Queue<string>();
            public static int NextInt() => int.Parse(NextString());
            public static long NextLong() => long.Parse(NextString());
            public static string NextString()
            {
                if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item);
                return param.Dequeue();
            }
        }
        static public void Main(string[] args)
        {
            var N = Console_.NextInt();
            var M = Console_.NextInt();

            var nodeTable = new Dijkstra.Node[N];
            var algo = new Dijkstra();
            for (int i = 0; i < N; ++i)
            {
                var node = new Dijkstra.Node();
                if (i == 0)
                {
                    node.d = 0;
                    node.isDInit = true;
                    node.close = false;
                }
                nodeTable[i] = node;
                algo.AddNode(node);
            }

            for (int i = 0; i < M; ++i)
            {
                var a = Console_.NextInt();
                var b = Console_.NextInt();
                var c = Console_.NextLong();

                nodeTable[a - 1].neighbor.Add(Tuple.Create(c, nodeTable[b - 1]));
            }

            algo.Solve();

            Console.WriteLine(nodeTable[N - 1].d >= 20000000000000 ? "inf" : nodeTable[N - 1].d.ToString());
        }


        class Dijkstra
        {
            public class Node
            {
                public long d;
                public bool isDInit = false;
                public Node parent = null;
                public List<Tuple<long, Node>> neighbor = new List<Tuple<long, Node>>();
                public int id;
                public bool close = true;
            }
            private IList<int> heap = new List<int>();
            private IList<Node> dic = new List<Node>();
            private void Push(int n)
            {
                var idx = heap.Count;
                heap.Add(n);
                while (idx != 0)
                {
                    var parentIdx = (idx - 1) / 2;
                    if (dic[n].d < dic[heap[parentIdx]].d) break;
                    heap[idx] = heap[parentIdx];
                    idx = parentIdx;
                }
                heap[idx] = n;
            }
            private int Pop()
            {
                var ret = heap[0];
                var x = heap[heap.Count - 1];
                heap.RemoveAt(heap.Count - 1);
                if (heap.Count == 0) return ret;
                var idx = 0;
                while (idx * 2 + 1 < heap.Count)
                {
                    var childIdx1 = idx * 2 + 1;
                    var childIdx2 = idx * 2 + 2;
                    if (childIdx2 < heap.Count && dic[heap[childIdx1]].d < dic[heap[childIdx2]].d) childIdx1 = childIdx2;
                    if (dic[heap[idx]].d > dic[heap[childIdx1]].d) break;
                    heap[idx] = heap[childIdx1];
                    idx = childIdx1;
                }
                heap[idx] = x;
                return ret;
            }
            public void AddNode(Node n)
            {
                n.id = dic.Count;
                dic.Add(n);
                Push(n.id);
            }

            public void Solve()
            {
                while (heap.Count != 0)
                {
                    var tgtNode = Pop();
                    if (dic[tgtNode].close)
                    {
                        continue;
                    }
                    dic[tgtNode].close = true;
                    foreach (var item in dic[tgtNode].neighbor)
                    {
                        var dtmp = dic[tgtNode].d + item.Item1;
                        if (!item.Item2.isDInit || (item.Item2.d < dtmp && item.Item2.d != 20000000000000))
                        {
                            item.Item2.parent = dic[tgtNode];

                            var tmpNode = item.Item2.parent;
                            var beforeD = 0L;
                            var isInf = false;
                            while (tmpNode != null)
                            {
                                if (tmpNode.id == item.Item2.id)
                                {
                                    if (beforeD < dtmp)
                                    {
                                        isInf = true;
                                    }
                                    break;
                                }
                                beforeD = tmpNode.d;
                                tmpNode = tmpNode.parent;
                            }

                            item.Item2.isDInit = true;
                            item.Item2.d = isInf ? 20000000000000 : dtmp;
                            item.Item2.close = false;
                            Push(item.Item2.id);
                        }
                    }
                }
            }
        }
    }
}