static void MainF(string[] args) { #if false Reader = new StreamReader(@"Graph\MST\test\test.txt"); #else Reader = new StreamReader(Console.OpenStandardInput()); #endif t = ReadInt(); for (int i = 0; i < t; i++) { ns = ReadIntArray(); n = ns[0]; m = ns[1]; dis = new double[n, n]; for (int k = 0; k < n; k++) { for (int h = k + 1; h < n; h++) { dis[k, h] = double.MaxValue; } } List <Pair>[] graph = Enumerable.Range(0, n).Select(s => new List <Pair>()).ToArray();; for (int k = 0; k < m; k++) { ns = ReadIntArray(); var s = ns[0] - 1; var d = ns[1] - 1; var weight = Math.Log10(ns[2]); graph[s].Add(new Pair(s, d, weight) { We = ns[2] }); graph[d].Add(new Pair(d, s, weight) { We = ns[2] }); } List <Pair> path; MinimumSpanningTree.GetMinimumSpanningTree(graph, out path); long result = 1; foreach (var item in path) { result = (result * item.We) % 1000000007; } Console.WriteLine(result); } Reader.Close(); }
public static int GetMinimumCost(int[,] graph, int k) { var costs = WarshallShortestPath.GetShortestCostsAndPath(graph).Item1; var newGraph = Enumerable.Range(0, k).Select(e => new List <Pair>()).ToArray(); for (int a = 0; a < k; a++) { for (int b = a + 1; b < k; b++) { newGraph[a].Add(new Pair(a, b, costs[a, b])); newGraph[b].Add(new Pair(b, a, costs[a, b])); } } List <Pair> path; return(MinimumSpanningTree.GetMinimumSpanningTree(newGraph, out path)); }