public double CompareRoot <TVertex, TEdge>(IUndirectedGraph <TVertex, TEdge> g)
            where TEdge : IEdge <TVertex>
        {
            var distances = new Dictionary <TEdge, double>();

            foreach (var e in g.Edges)
            {
                distances[e] = g.AdjacentDegree(e.Source) + 1;
            }

            var prim    = new List <TEdge>(g.MinimumSpanningTreePrim(e => distances[e]));
            var kruskal = new List <TEdge>(g.MinimumSpanningTreeKruskal(e => distances[e]));

            var primCost    = prim.Sum(e => distances[e]);
            var kruskalCost = kruskal.Sum(e => distances[e]);

            TestConsole.WriteLine("prim cost: {0}", primCost);
            TestConsole.WriteLine("kruskal cost: {0}", kruskalCost);
            if (primCost != kruskalCost)
            {
                GraphConsoleSerializer.DisplayGraph(g);
                TestConsole.WriteLine("prim: {0}", String.Join(", ", Array.ConvertAll(prim.ToArray(), e => e.ToString() + ':' + distances[e])));
                TestConsole.WriteLine("krus: {0}", String.Join(", ", Array.ConvertAll(kruskal.ToArray(), e => e.ToString() + ':' + distances[e])));
                Assert.Fail("cost do not match");
            }

            return(kruskalCost);
        }
        protected static void Prim <TVertex, TEdge>([NotNull] IUndirectedGraph <TVertex, TEdge> graph)
            where TEdge : IEdge <TVertex>
        {
            var distances = new Dictionary <TEdge, double>();

            foreach (TEdge edge in graph.Edges)
            {
                distances[edge] = graph.AdjacentDegree(edge.Source) + 1;
            }

            IEnumerable <TEdge> edges = graph.MinimumSpanningTreePrim(e => distances[e]);

            AssertSpanningTree(graph, edges);
        }
        private static double CompareRoot <TVertex, TEdge>([NotNull] IUndirectedGraph <TVertex, TEdge> graph)
            where TEdge : IEdge <TVertex>
        {
            var distances = new Dictionary <TEdge, double>();

            foreach (TEdge edge in graph.Edges)
            {
                distances[edge] = graph.AdjacentDegree(edge.Source) + 1;
            }

            TEdge[] prim    = graph.MinimumSpanningTreePrim(e => distances[e]).ToArray();
            TEdge[] kruskal = graph.MinimumSpanningTreeKruskal(e => distances[e]).ToArray();

            double primCost    = prim.Sum(e => distances[e]);
            double kruskalCost = kruskal.Sum(e => distances[e]);

            if (Math.Abs(primCost - kruskalCost) > double.Epsilon)
            {
                Assert.Fail("Cost do not match.");
            }

            return(kruskalCost);
        }