Ejemplo n.º 1
0
 public long Solve(long nodeCount, long[][] edges)
 {
     Node[] graph = new Node[nodeCount + 1];
     Q1MinCost.BuildGraph(edges, graph);
     graph[1].Weight = 0;
     return(BellmanFord(graph, edges));
 }
Ejemplo n.º 2
0
        public string[] Solve(long nodeCount, long[][] edges, long startNode)
        {
            Node[] graph = new Node[nodeCount + 1];
            Q1MinCost.BuildGraph(edges, graph);
            var        infinitePossible = BellmanFord(graph, edges, startNode);
            List <int> NegativeCycle    = new List <int>();

            while (infinitePossible.Any())
            {
                var temp = infinitePossible.Dequeue();
                TravelBack(graph, temp);
            }
            List <string> result = new List <string>();

            for (int i = 1; i < graph.Length; i++)
            {
                if (graph[i].Weight == Max)
                {
                    result.Add("*");
                }
                else if (graph[i].IsChecked)
                {
                    result.Add("-");
                }
                else
                {
                    result.Add(graph[i].Weight.ToString());
                }
            }

            return(result.ToArray());
        }