is doing a contest. He comes across the following problem:
You have a weighted graph of
knows that one fast solution uses Kruskal's algorithm with a Disjoint Set data structure. He practices that data structure every day, but still somehow manages to get it wrong. Will you show him a working example?
recalls that Kruskal's algorithm goes through all the edges one by one sorted by nondecreasing edge weight. An edge will be added to the minimum spanning tree if the two vertices it connects were not connected by any path so far.
Input Specification
The first line has
The
Output Specification
If no minimum spanning tree exists, output Disconnected Graph
.
Otherwise, output
Sample Input 1
4 4
1 2
1 3
2 3
3 4
Sample Output 1
1
2
4
Sample Input 2
3 1
1 2
Sample Output 2
Disconnected Graph
Comments
This comment is hidden due to too much negative feedback. Show it anyway.
This comment is hidden due to too much negative feedback. Show it anyway.
https://dmoj.ca/problem/ds2/submissions/Xyene/
He did
This comment is hidden due to too much negative feedback. Show it anyway.
Well to make logarithmic time TLE would require massive amount of input. So there really isn't a good way of penalizing people for using link-cut trees.
Some simple disjoint set implementations (i.e. Only using union-by-rank optimization) take
time per operation
edit: Google Code Jam's problem preparation guide also heavily discourages against trying to differentiate between
and 
in problems
Well that's certainly one way to solve it, but not the only way (or the intended way).