public void Solve() { //ABC061 D int N = NextInt(), M = NextInt(); var bf = new BellmanFord(N); M.REP(i => { int ai = NextInt() - 1, bi = NextInt() - 1, ci = NextInt(); bf.Add(ai, bi, -ci); }); bf.Run(0); if (bf.HasCycle) { "inf".WL(); } else { (-bf.Distance[N - 1]).WL(); } return; }