Exemple #1
0
    public static void Main(string[] args)
    {
        N = Input.NextInt();
        M = Input.NextInt();

        var nodes = Enumerable.Range(0, N).Select(n => new BellmanFord.Node()).ToArray();

        var edges = new List <BellmanFord.Edge>();

        for (int i = 0; i < M; i++)
        {
            var abc = Input.LineInt();
            var a   = abc[0] - 1;
            var b   = abc[1] - 1;
            var c   = -abc[2];

            var ef = nodes[a].CreateEdge(nodes[b], c);
            edges.Add(ef);
        }

        var search = new BellmanFord();

        search.Search(nodes, edges, nodes[0]);

        var negOfMaxCost = nodes[N - 1].MinDistance;

        Console.WriteLine(negOfMaxCost == long.MinValue ? "inf" : (-negOfMaxCost).ToString());
    }