Constructing the graph using edge