C++ implementation of Minimum Spanning Tree