Can someone provide me with a good implementation of the offline solution of the fully dynamic connectivity problem ? I think I got the idea but I'm having trouble implementing it. UPD: Guys I found the stupid bug in my implementation. I am sharing my code right now (my implementation is with segment tree instead of divide and conquer, which is pretty much the same) and I hope you will find it helpful. Code