function for reading graph from file