implementing graph theory algorithm