simple graph algo implementation