Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()


int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n; cin >> n;
	vector<pair<ll, ll> > d(n);
	for(int i = 0; i < n; i++) {
		ll x; cin >> x;
		d[i] = make_pair(x, i);
	}
	vector<int> sz(n, 1);
	sort(all(d), greater<pair<ll,ll>>());
	vector<pair<int, int> > edges;
	vector<int> adj(n);
	for(int i = 0; i < n - 1; i++) {
		ll id = d[i].se, dis = d[i].fi;
		int dt = n - 2*sz[id];
		dis -= dt;
		auto it = lower_bound(all(d), pair<ll, ll>(dis, n), greater<pair<ll, ll> >());
		if(it == d.end() || it->fi != dis) {
			cout << "-1\n";
			return 0;
		}
		sz[it->se] += sz[id];
		adj[it->se].emplace_back(id);
		edges.emplace_back(id + 1, it->se + 1);
	}
	function<ll(int, int)> dfs = [&](int u) {
		ll ret = 0;
		for(auto &v : adj) {
			ret += dfs(v) + sz[v];
		}
		return ret;
	};
	if(dfs(id[n-1]) != d[n-1].fi) {
		cout << "-1\n";
		return 0;
	}
	sort(all(edges));
	for(auto &e : edges) {
		cout << e.fi << ' ' << e.se << '\n';
	}
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:35:29: error: request for member 'emplace_back' in 'adj.std::vector<int>::operator[](((std::vector<int>::size_type)it.__gnu_cxx::__normal_iterator<std::pair<long long int, long long int>*, std::vector<std::pair<long long int, long long int> > >::operator->()->std::pair<long long int, long long int>::second))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   35 |                 adj[it->se].emplace_back(id);
      |                             ^~~~~~~~~~~~
a.cc: In lambda function:
a.cc:41:35: error: no match for call to '(std::function<long long int(int, int)>) (int&)'
   41 |                         ret += dfs(v) + sz[v];
      |                                ~~~^~~
In file included from /usr/include/c++/14/functional:59,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/std_function.h:587:7: note: candidate: '_Res std::function<_Res(_ArgTypes ...)>::operator()(_ArgTypes ...) const [with _Res = long long int; _ArgTypes = {int, int}]'
  587 |       operator()(_ArgTypes... __args) const
      |       ^~~~~~~~
/usr/include/c++/14/bits/std_function.h:587:7: note:   candidate expects 2 arguments, 1 provided
a.cc: In function 'int main()':
a.cc:38:38: error: conversion from 'main()::<lambda(int)>' to non-scalar type 'std::function<long long int(int, int)>' requested
   38 |         function<ll(int, int)> dfs = [&](int u) {
      |                                      ^~~~~~~~~~~~
   39 |                 ll ret = 0;
      |                 ~~~~~~~~~~~           
   40 |                 for(auto &v : adj) {
      |                 ~~~~~~~~~~~~~~~~~~~~  
   41 |                         ret += dfs(v) + sz[v];
      |                         ~~~~~~~~~~~~~~~~~~~~~~
   42 |                 }
      |                 ~                     
   43 |                 return ret;
      |                 ~~~~~~~~~~~           
   44 |         };
      |         ~                             
a.cc:45:16: error: 'id' was not declared in this scope; did you mean 'd'?
   45 |         if(dfs(id[n-1]) != d[n-1].fi) {
      |                ^~
      |                d