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,\dots,e_k\in E$$$ such that there exists a sequence of distinct vertices, $$$v_1,\dots,v_{k+1}$$$, satisfying the following conditions.
We can define distances and trees now. Given two vertices $$$u,v\in V$$$, the distance $$$\delta(u,v)$$$ from $$$u$$$ to $$$v$$$ is $$$0$$$ if $$$u=v$$$. If there exists a path from $$$u$$$ to $$$v$$$, then $$$\delta(u,v)$$$ is the minimum number of edges required to form a path from $$$u$$$ to $$$v$$$. Otherwise, $$$\delta(u,v)=\infty$$$. 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,\dots,d_n$$$ and asks you to construct a tree $$$G_T=(V_T,E_T)$$$ satisfying the following conditions.
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,\dots,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.
5 0 1 2 1 3
-1
5 1 1 0 1 1
3 1 3 2 3 4 3 5
| Name |
|---|


