common graph algorithm in go