Sort the edges, then take them lightest first, skipping any edge that would close a cycle. A union-find forest says which is which.
This interactive visualization needs JavaScript.