Language: C++

#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
#define int long long
int n,size[100100],u[100100],v[100100],head[100100],cnt,D;
struct Edge{
	int to,nxt;
}edge[200100];
struct node{
	int dis,x;
	bool operator<(node b)const{
		return dis>b.dis;
	}
}a[100100];
map<int,int>mp;
void addedge(int x,int y){
	edge[++cnt].to=y;
	edge[cnt].nxt=head[x];
	head[x]=cnt;
}
int dfs(int x,int fa,int now){
	D+=now;
	for (int i=head[x];i;i=edge[i].nxt){
		int upup=edge[i].to;
		if(upup==fa)continue;
		dfs(upup,x,now+1);
	}
}
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i].dis);
		a[i].x=i;
		mp[a[i].dis]=i;
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)size[i]=1;
	for(int i=1;i<n;i++){
		int dis=a[i].dis,x=a[i].x;
		int tmp=dis-abs(n-2*size[x]);
		int fa=mp.find(tmp)->second;
		if(fa==x||!fa)return puts("-1"),0;
		size[fa]+=size[x];
		u[i]=x,v[i]=fa;
		addedge(x,fa);
		addedge(fa,x);
	}
	dfs(a[n].x,0,0);
	if(D!=a[n].dis)return puts("-1"),0;
	for(int i=1;i<n;i++)
		printf("%lld %lld\n",u[i],v[i]);
}

Compiler output:
a.cc: In function 'long long int dfs(long long int, long long int, long long int)':
a.cc:29:1: warning: no return statement in function returning non-void [-Wreturn-type]
   29 | }
      | ^
a.cc: In function 'int main()':
a.cc:38:30: error: reference to 'size' is ambiguous
   38 |         for(int i=1;i<=n;i++)size[i]=1;
      |                              ^~~~
In file included from /usr/include/c++/14/map:65,
                 from a.cc:2:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:6:7: note:                 'long long int size [100100]'
    6 | int n,size[100100],u[100100],v[100100],head[100100],cnt,D;
      |       ^~~~
a.cc:41:37: error: reference to 'size' is ambiguous
   41 |                 int tmp=dis-abs(n-2*size[x]);
      |                                     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:6:7: note:                 'long long int size [100100]'
    6 | int n,size[100100],u[100100],v[100100],head[100100],cnt,D;
      |       ^~~~
a.cc:44:17: error: reference to 'size' is ambiguous
   44 |                 size[fa]+=size[x];
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:6:7: note:                 'long long int size [100100]'
    6 | int n,size[100100],u[100100],v[100100],head[100100],cnt,D;
      |       ^~~~
a.cc:44:27: error: reference to 'size' is ambiguous
   44 |                 size[fa]+=size[x];
      |                           ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:6:7: note:                 'long long int size [100100]'
    6 | int n,size[100100],u[100100],v[100100],head[100100],cnt,D;
      |       ^~~~