Distance and Tree

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

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 GG is a pair (V,E)(V, E), where VV is a set and EE is a set of unordered pairs of VV’s elements. For a graph G=(V,E)G = (V, E), we call VV as GG’s vertex set and EE as GG’s edge set. Elements in VV are vertices, and elements in EE are edges.

Let uu and vv be vertices in VV. A path from uu to vv of length kk is a sequence of edges e_1,e_2,,e_kEe\_1, e\_2, \dots , e\_k ∈ E such that there exists a sequence of distinct vertices, v_1,,v_k+1v\_1, \dots , v\_{k+1}, satisfying the following conditions.

  • u=v_1u = v\_1.
  • v=v_k+1v = v\_{k+1}.
  • e_i=v_i,v_i+1e\_i = \\{v\_i , v\_{i+1}\\}.

If pp is a path from uu to vv, then uu and vv are connected by pp.

We can define distances and trees now. Given two vertices u,vVu, v ∈ V, the distance δ(u,v)δ(u, v) from uu to vv is 00 if u=vu = v. If there exists a path from uu to vv, then δ(u,v)δ(u, v) is the minimum number of edges required to form a path from uu to vv. Otherwise, δ(u,v)=δ(u, v) = ∞. A tree is an undirected graph in which any distinct two vertices uu and vv are connected by exactly one path.

Danny gives you a sequence of non-negative integers d_1,d_2,,d_nd\_1, d\_2, \dots , d\_n and asks you to construct a tree G_T=(V_T,E_T)G\_T = (V\_T , E\_T ) satisfying the following conditions.

  • The vertex set V_T=p_1,,p_nV\_T = \\{p\_1, \dots , p\_n\\} is a set of points on a two dimensional Euclidean plane. For 1kn1 ≤ k ≤ n, the coordinate of p_kp\_k is (coskθ,sinkθ)(\cos{kθ}, \sin{kθ}) where θ=2πnθ = 2π n.
  • For any two distinct edges p_a,p_b\\{p\_a, p\_b\\} and q_a,q_b\\{q\_a, q\_b\\} in E_TE\_T, the line segments p_ap_bp\_ap\_b and q_aq_bq\_aq\_b do not intersect unless those two edges share a common vertex (that is, p_a,p_bq_a,q_b\\{p\_a, p\_b\\}∩\\{q\_a, q\_b\\} ≠ ∅).
  • There exists a vertex rr such that δ(r,p_k)=d_kδ(r, p\_k) = d\_k for 1kn1 ≤ k ≤ n. We call rr as the root of G_TG\_T.

If there exists such tree graph, please output the edge set E_TE\_T. Otherwise, output 1-1.

입력

The first line contains a positive integer nn indicating the number of vertices of the tree to be constructed. The second line contains nn non-negative integers d_1,,d_nd\_1, \dots , d\_n, the sequence given by Danny.

출력

If there does not exist such a tree G_TG\_T, output 1-1. Otherwise, output n1n - 1 lines to represent the edge set E_TE\_T. The ii-th line should contain two space-separated integers u_iu\_i and v_iv\_i. The ii-th edge in E_TE\_T should be p_u_i,p_v_i\\{p\_{u\_i} , p\_{v\_i}\\}. If there are multiple solutions, you may output any of them.

제한

  • 2n1000002 ≤ n ≤ 100000
  • For 1kn1 ≤ k ≤ n, 0d_kn10 ≤ d\_k ≤ n - 1.