Exemple #1
0
        static void Main()
        {
            var h = Read();
            int n = h[0], m = h[1];
            var es = Array.ConvertAll(new bool[m], _ => Read());

            var(c, inEdges) = ShortestPath0.Dijkstra(n + 1, es, false, 1, n);
            if (inEdges[n] == null)
            {
                Console.WriteLine(-1); return;
            }

            var path = ShortestPath0.GetPathVertexes(inEdges, n);

            Console.WriteLine(string.Join(" ", path));
        }
        static void Main()
        {
            var h = Read();
            int n = h[0], m = h[1], s = h[2], t = h[3];
            var es = Array.ConvertAll(new bool[m], _ => Read());

            var(c, inEdges) = ShortestPath0.Dijkstra(n, es, true, s, t);
            if (inEdges[t] == null)
            {
                Console.WriteLine(-1); return;
            }

            var path = ShortestPath0.GetPathEdges(inEdges, t);

            Console.WriteLine($"{c[t]} {path.Length}");
            Console.WriteLine(string.Join("\n", path.Select(e => $"{e[0]} {e[1]}")));
        }