algo2: graph implemented