completed functions on graph.cpp