KurskalA algorithm implementation