12058 - Tsai_DS_1108_MST   

Description

MST Algorithms :

1. Kruskal's Algorithm

2. Prim's Algorithm

3. Sollin's Algorithm

Please implement one of the above algorithms by C++ code.

Graph rules :

The graph is a undirected graph, contains at most 10 nodes named 0 ~ 9.

There are multiple edges between two nodes.

The weight of all edges are under 101.

Hint : 

If you want to transform type string to type int, you can follow the following pseudo code.

   #include<cstdlib>

   string str = '123';

   int x = atoi(str.c_str());

 

Input

First, you will have several lines to tell you which two nodes are connected and the weight of the edge between the two nodes, the format is below.

1 2 4

The red part is node No.1.

The green part is node No.2.

The blue part is the weight of the edge between node 1 and 2.

Finally, you will get "end".

Note : There is one graph in one test case.

 

Output

When you get "end", you need to print out the total of weight in MST and a '\n at the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss