Graph problems are popular in competitive programming, and problems related to distanceis and trees appear frequently. Let us start with some definitions.
A set is a collection of distinct elements. An undirected simple graph G is a pair (V,E), where V is a set and E is a set of unordered pairs of V’s elements. For a graph G=(V,E), we call V as G’s vertex set and E as G’s edge set. Elements in V are vertices, and elements in E are edges.
Let u and v be vertices in V. A path from u to v of length k is a sequence of edges e_1,e_2,…,e_k∈E such that there exists a sequence of distinct vertices, v_1,…,v_k+1, satisfying the following conditions.
If p is a path from u to v, then u and v are connected by p.
We can define distances and trees now. Given two vertices u,v∈V, the distance δ(u,v) from u to v is 0 if u=v. If there exists a path from u to v, then δ(u,v) is the minimum number of edges required to form a path from u to v. Otherwise, δ(u,v)=∞. A tree is an undirected graph in which any distinct two vertices u and v are connected by exactly one path.
Danny gives you a sequence of non-negative integers d_1,d_2,…,d_n and asks you to construct a tree G_T=(V_T,E_T) satisfying the following conditions.
If there exists such tree graph, please output the edge set E_T. Otherwise, output −1.
The first line contains a positive integer n indicating the number of vertices of the tree to be constructed. The second line contains n non-negative integers d_1,…,d_n, the sequence given by Danny.
If there does not exist such a tree G_T, output −1. Otherwise, output n−1 lines to represent the edge set E_T. The i-th line should contain two space-separated integers u_i and v_i. The i-th edge in E_T should be p_u_i,p_v_i. If there are multiple solutions, you may output any of them.