Kruskals algorithm in PHP