Beispiel #1
0
        public static IList <string> Answer(IList <string> inputs)
        {
            var gis   = new AdjacencyListGraphInput(inputs);
            var g     = gis.ToEdges();
            var start = gis.NextAsIndex();


            var path = ShortestPath(start, g.Item1, g.Item2.ToList());

            return(path.Distance.Values
                   .Select(v =>
            {
                switch (v)
                {
                case NegativeInfinity:
                    return "-";

                case PositiveInfinity:
                    return "*";

                default:
                    return v.ToString();
                }
            })
                   .ToArray());
        }
Beispiel #2
0
        public static IList <string> Answer(IList <string> inputs)
        {
            var gis = new AdjacencyListGraphInput(inputs);
            var g   = gis.ToEdges();

            var answer = HasNegativeCycle(g.Item1, g.Item2.ToList()) ? "1" : "0";

            return(new[] { answer });
        }
Beispiel #3
0
        public static IList <string> Answer(IList <string> inputs)
        {
            var gi     = new AdjacencyListGraphInput(inputs);
            var graph  = gi.ToDirectedAdjacencyGraph();
            var points = gi.NextAsEdge();
            //Console.WriteLine(graph);

            var s    = new DijkstrasAlgorithm(graph);
            var cost = s.LowestCostPath(points.Left, points.Right);

            return(new[] { cost.ToString() });
        }