Ask me last semester 😉 Look at Kruskal's/Dijkstra's algorithms (whatever is used for shortest-path, I don't remember), and maybe keep a list of nodes in each tree or something. It would probably be O(m*O(algorithm)) where m is the number of trees and the algorithm is the shortest-path algorithm (google it), but I haven't given it any thought.
edit: Is the graph directed? If it is, I have no idea, unless you start off knowing each root.