Check if edge is included in SOME MST in linear time (non-distinct values)
We will solve this using MST cycle property, which says that, "For any cycle C in the graph, if the weight of an edge e of C is larger than the weights of all other edges of C, then this edge cannot belong to an MST."
Now, run the following O(E+V)
algorithm to test if the edge E connecting vertices u and v will be a part of some MST or not.
Step 1
Run dfs from one of the end-points(either u or v) of the edge E considering only those edges that have weight less than that of E.
Step 2
Case 1 If at the end of this dfs, the vertices u and v get connected, then edge E cannot be a part of some MST. This is because in this case there definitely exists a cycle in the graph with the edge E having the maximum weight and it cannot be a part of the MST(from the cycle property).
Case 2 But if at the end of the dfs u and v stay disconnected, then edge E must be the part of some MST as in this case E is always not the maximum weight edge in all the cycles that it is a part of.
I will write down my thoughts about this problem.
The cycle property is very important in here: The largest edge in any cycle can't be in a minimum spanning tree.
To prove the cycle property, suppose that there is a minimum spanning tree T that contains the edge e which is the largest cost edge in a cycle. Then we can delete the edge e in tree T and we get two sets S and T. Then the cycle must contain some edge other than e that connects the sets S and T. Then from the cut property, the edge e can't be in a minimum spanning tree.
Once we have the cycle property, then we go on to make a claim about whether some edge e is in a minimum spanning tree:
The edge e(v,w) doesn't belong to any minimum spanning tree if and only if there is a path from v and w where every edge on this path is smaller than e.
Using the above claim, the algorithm goes as follows:
Delete all the edges larger than e, now we have the graph G'. Run DFS to check if v and w are connected in G'. If v and w are still connected, then edge e doesn't belong to any minimum spanning tree. If v and w are not connected, then edge e is in some minimum spanning tree.