c++ implementation of kruskals algo