accomplish undirected graph and directed graph