Submission #9813519
Source Code Expand
#include <bits/stdc++.h>
#define reg register
#define pr std::pair<ll, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;
namespace modular {
const int MOD = 1000000007;
inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
inline int mul(int x, int y) { return 1LL * x * y % MOD; }
inline int qpow(int x, int y) {
int ans = 1;
for (; y; y >>= 1, x = mul(x, x))
if (y & 1)
ans = mul(ans, x);
return ans;
}
}; // namespace modular
namespace Base {
template <typename Tp> inline Tp input() {
Tp x = 0, y = 1;
char c = getchar();
while ((c < '0' || '9' < c) && c != EOF) {
if (c == '-')
y = -1;
c = getchar();
}
if (c == EOF)
return 0;
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x *= y;
}
template <typename Tp> inline void read(Tp &x) { x = input<Tp>(); }
template <typename Tp> inline void chmax(Tp &x, Tp y) { x < y ? x = y : 0; }
template <typename Tp> inline void chmin(Tp &x, Tp y) { x > y ? x = y : 0; }
}; // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/
#define MAX_N 200007
#define V std::vector
int N;
int sz[MAX_N];
ll d[MAX_N];
pr a[MAX_N];
V<int> G[MAX_N];
std::map<ll, int> mp;
void dfs1(int x, int las) {
sz[x] = 1;
for (int y : G[x])
if (y != las) {
dfs1(y, x);
sz[x] += sz[y];
d[x] += d[y] + sz[y];
}
}
bool dfs2(int x, int las) {
if (mp[d[x]] != x)
return false;
for (int y : G[x])
if (y != las) {
d[y] = d[x] + N - 2 * sz[y];
if (!dfs2(y, x))
return false;
}
return true;
}
void solve() {
std::sort(a + 1, a + N + 1);
Rep(i, N) sz[i] = 1, mp[a[i].fi] = a[i].se;
ILep(i, N) {
int u = a[i].se, s = N - 2 * sz[u], v;
if (mp.count(a[i].fi - s)) {
v = mp[a[i].fi - s];
sz[v] += sz[u];
G[u].push_back(v);
G[v].push_back(u);
} else
return puts("-1"), void();
}
dfs1(1, 0);
if (!dfs2(1, 0))
return puts("-1"), void();
Rep(i, N) {
for (int j : G[i])
if (i < j)
printf("%d %d\n", i, j);
}
}
int main() {
#ifdef LOCAL
FIN("in");
#endif
read(N);
Rep(i, N) read(a[i].fi), a[i].se = i;
solve();
return 0;
}
Submission Info
Submission Time |
|
Task |
F - Distance Sums |
User |
vjudge3 |
Language |
C++14 (GCC 5.4.1) |
Score |
900 |
Code Size |
3127 Byte |
Status |
AC |
Exec Time |
124 ms |
Memory |
27392 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
900 / 900 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample1.txt, sample2.txt, sample3.txt |
All |
sample1.txt, sample2.txt, sample3.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 3.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 4.txt, 40.txt, 41.txt, 42.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name |
Status |
Exec Time |
Memory |
1.txt |
AC |
4 ms |
8576 KB |
10.txt |
AC |
120 ms |
25984 KB |
11.txt |
AC |
64 ms |
16768 KB |
12.txt |
AC |
50 ms |
15488 KB |
13.txt |
AC |
74 ms |
17536 KB |
14.txt |
AC |
123 ms |
27392 KB |
15.txt |
AC |
115 ms |
25088 KB |
16.txt |
AC |
118 ms |
23296 KB |
17.txt |
AC |
124 ms |
23552 KB |
18.txt |
AC |
53 ms |
15872 KB |
19.txt |
AC |
121 ms |
26368 KB |
2.txt |
AC |
3 ms |
6400 KB |
20.txt |
AC |
122 ms |
23808 KB |
21.txt |
AC |
43 ms |
12544 KB |
22.txt |
AC |
122 ms |
23808 KB |
23.txt |
AC |
121 ms |
25600 KB |
24.txt |
AC |
106 ms |
24576 KB |
25.txt |
AC |
48 ms |
15360 KB |
26.txt |
AC |
50 ms |
15488 KB |
27.txt |
AC |
49 ms |
15360 KB |
28.txt |
AC |
43 ms |
15104 KB |
29.txt |
AC |
117 ms |
23936 KB |
3.txt |
AC |
12 ms |
10240 KB |
30.txt |
AC |
116 ms |
24192 KB |
31.txt |
AC |
121 ms |
23680 KB |
32.txt |
AC |
116 ms |
24832 KB |
33.txt |
AC |
86 ms |
20992 KB |
34.txt |
AC |
116 ms |
23680 KB |
35.txt |
AC |
83 ms |
22784 KB |
36.txt |
AC |
85 ms |
22144 KB |
37.txt |
AC |
119 ms |
24064 KB |
38.txt |
AC |
118 ms |
23552 KB |
39.txt |
AC |
123 ms |
26496 KB |
4.txt |
AC |
7 ms |
7168 KB |
40.txt |
AC |
120 ms |
25600 KB |
41.txt |
AC |
120 ms |
22656 KB |
42.txt |
AC |
92 ms |
20352 KB |
5.txt |
AC |
52 ms |
16256 KB |
6.txt |
AC |
117 ms |
26368 KB |
7.txt |
AC |
119 ms |
25600 KB |
8.txt |
AC |
117 ms |
25216 KB |
9.txt |
AC |
121 ms |
24704 KB |
sample1.txt |
AC |
4 ms |
8448 KB |
sample2.txt |
AC |
3 ms |
6400 KB |
sample3.txt |
AC |
4 ms |
8448 KB |