Constructing graph