atcoder#CODEFESTIVAL2016EXA. Distance Pairs
Distance Pairs
Score : points
Problem Statement
There is an undirected connected graph with vertices numbered through . The lengths of all edges in this graph are . It is known that for each , the distance between vertex and vertex is , and the distance between vertex and vertex is . Determine whether there exists such a graph. If it exists, find the minimum possible number of edges in it.
Constraints
Input
The input is given from Standard Input in the following format:
:
Output
If there exists a graph satisfying the conditions, print the minimum possible number of edges in such a graph. Otherwise, print -1
.
4
0 1
1 0
1 1
2 1
4
The figure below shows two possible graphs. The graph on the right has fewer edges.
3
0 1
1 0
2 2
-1
Such a graph does not exist.