Language: C++

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <queue>
#include <vector>
#define int long long

using namespace std;

inline int read()
{
    int x=0,f=1;char ch=getchar();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    return x*f;
}

pair <long long,int> D[100050];

pair <int,int> edge[100050];

vector <int> G[100050];

int n,size[100050],tot;

long long dis[100050];

inline void dfs(int u,int fa)
{
    for (int i=0;i<G[u].size();i++)
    {
        int v=G[u][i];
        if (v!=fa)
        {
            dis[v]=dis[u]+1;
            dfs(v,u);
        }
    }
}

int main()
{
    n=read();
    for (int i=1;i<=n;i++)
    {
        int d=read();
        D[i]={d,i};
        size[i]=1;
    }
    sort(D+1,D+n+1);
    reverse(D+1,D+n+1);
    for (int i=1;i<n;i++)
    {
        long long delta=D[i].first-n+2*size[i];
        int l=1,r=n+1,pos=0; 
        while (l<=r)
        {
            int mid=(l+r)>>1;
            if (D[mid].first<=delta)
            {
                r=mid-1;
                pos=mid;
            }
            else
                l=mid+1;
        }
        //cout << D[pos].first << " " << delta << endl;
        if (D[pos].first!=delta)
        {
            puts("-1");
            return 0;
        }
        int u=D[i].second,v=D[pos].second;
        G[u].push_back(v);
        G[v].push_back(u);
        edge[++tot]={u,v};
        size[pos]+=size[i];
    }   
    dfs(D[n].second,0);
    long long sum=0;
    for (int i=1;i<=n;i++)
        sum+=dis[i];
    if (sum==D[n].first)
    {
        for (int i=1;i<=tot;i++)
            cout << edge[i].first << " " << edge[i].second << endl;
    }
    else
        puts("-1");
    return 0;
}

Compiler output:
cc1plus: error: '::main' must return 'int'
a.cc: In function 'int main()':
a.cc:51:9: error: reference to 'size' is ambiguous
   51 |         size[i]=1;
      |         ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/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:27:7: note:                 'long long int size [100050]'
   27 | int n,size[100050],tot;
      |       ^~~~
a.cc:57:40: error: reference to 'size' is ambiguous
   57 |         long long delta=D[i].first-n+2*size[i];
      |                                        ^~~~
/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:27:7: note:                 'long long int size [100050]'
   27 | int n,size[100050],tot;
      |       ^~~~
a.cc:80:9: error: reference to 'size' is ambiguous
   80 |         size[pos]+=size[i];
      |         ^~~~
/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:27:7: note:                 'long long int size [100050]'
   27 | int n,size[100050],tot;
      |       ^~~~
a.cc:80:20: error: reference to 'size' is ambiguous
   80 |         size[pos]+=size[i];
      |                    ^~~~
/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:27:7: note:                 'long long int size [100050]'
   27 | int n,size[100050],tot;
      |       ^~~~