private static List <Edge> Solve(GraphClass graph, int nodes)
        {
            List <Edge> result = new List <Edge>();

            graph.Edges.Sort();
            foreach (var edge in graph.Edges)
            {
                if (!graph.IsConnected(edge.StartNode, edge.EndNode))
                {
                    if (graph.Connect(edge.StartNode, edge.EndNode, edge.Weight))
                    {
                        result.Add(edge);
                    }
                }
            }

            return(result);
        }
        static void Main(string[] args)
        {
            int nodes = int.Parse(Console.ReadLine().Split(' ')[1]);
            int edges = int.Parse(Console.ReadLine().Split(' ')[1]);

            GraphClass graph = new GraphClass(nodes);

            for (int i = 0; i < edges; i++)
            {
                var line = Console.ReadLine().Split(' ');

                int startNode = int.Parse(line[0]);
                int endNode   = int.Parse(line[1]);
                int weight    = int.Parse(line[2]);

                graph.AddEdge(new Edge(startNode, endNode, weight));
            }

            Console.WriteLine("Minimum spanning forest weight: {0}", Calc(Solve(graph, nodes)));
        }