A campus wants to connect n buildings with cable as cheaply as possible. Write PrimMst. Read n m and m undirected edges u v weight. Starting from vertex 0, grow a tree: keep the edges leaving the tree in a PriorityQueue ordered by weight, repeatedly take the cheapest one, skip it if its far end is already in the tree, otherwise add it and insert the new vertex's edges.
Print each edge added, then the total weight (or Graph is not connected: only k of n vertices reached) and how many stale edges were skipped (this last line depends on your implementation and is not checked).
For the input
5 7
0 1 2
0 3 6
1 2 3
1 3 8
1 4 5
2 4 7
3 4 9
the program prints
add 0 - 1 (2)
add 1 - 2 (3)
add 1 - 4 (5)
add 0 - 3 (6)
MST weight: 16 with 4 edges
Stale edges skipped: 0