Hi, everyone. Could anyone help me with the solution to this problem ?

For every node of the graph the distance from itself to the farthest node is given. We need to restore the initial graph, or report that no such graph exists. Number of nodes are up to 100000 and all the numbers are between 1 and N-1.