connect the nodes of a graph