Consider a number of vertices. They are separated into a number of Minimum Spanning Trees (MSTs) (so there's a forest of MSTs) using Kruskal's algorithm. For each vertex I need to know in which MST they are located. Each MST will be assigned a unique ID.
When completed I will know, for example, that Vertex #12 is in MST #2.
This is my best attempt at this. As you can see the algorithm failed because it falsely tagged one MST as two separate MSTs (Blue Group 0 and Blue Group 1):
I'm looking for an algorithm that can do this. Thanks in advance. I'm a programmer not a mathematician.
To answer questions from comments:
- MST = Minimum Spanning Tree
- I don't know in advance how many MSTs I'll end up with.
- Basically, I'm confronted with the forest of MSTs and then I have to count them and tag the vertices.

You can try nearest-neighbor clustering and adjust the criterion distance $d$: Nearest-neighbor clustering: