atcoder#ZONE2021F. 出会いと別れ

出会いと別れ

Score : 600600 points

Problem Statement

As your startup's new product, you are planning to build warp gates that allow travel between all planets. There are NN planets, numbered 00 through N1N-1, where there is an integer nn such that N=2nN = 2^n. To allow fast travel between all these planets, you want to make N1N - 1 warp gates, each of which allows instant travel between two planets. However, for some pairs of planets that are incompatible with each other, you cannot make a warp gate between them. More specifically, such pairs of planets incompatible with each other are represented by a sequence A=(A1,A2,,AM)A = (A_1, A_2, \dots, A_M). If and only if there is an integer ii such that a xor b=Aia\ \mathrm{xor}\ b = A_i, you cannot make a warp gate between Planet aa and Planet bb. Determine whether it is possible to make a network of warp gates allowing travel between every two planets. If it is possible, find one such way to make N1N - 1 warp gates.

What is $\mathrm{xor}$?

The bitwise xor\mathrm{xor} of integers aa and bb, a xor ba\ \mathrm{xor}\ b, is defined as follows:

  • When a xor ba\ \mathrm{xor}\ b is written in base two, the digit in the 2k2^k's place (k0k \geq 0) is 11 if exactly one of aa and bb is 11, and 00 otherwise.
$$3\ \mathrm{xor}\ 5 = 6$$$$011\ \mathrm{xor}\ 101 = 110 $$

Constraints

  • All values in input are integers.
  • There exists an integer nn such that 1n181 \leq n \leq 18 and N=2nN = 2^n.
  • 0MN10 \leq M \leq N - 1
  • 0<A1<A2<<AM<N0 < A_1 < A_2 < \dots < A_M < N

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 A2A_2 \cdots AMA_M

Output

If it is impossible to make a network of warp gates allowing travel between every two planets, print -1.

If it is possible to make such a network, print one way to make such N1N - 1 warp gates in the following format:

U1U_1 V1V_1

U2U_2 V2V_2

\vdots

UN1U_{N-1} VN1V_{N-1}

It means you make a warp gate between Planet UiU_i and Planet ViV_i.

4 1
3
1 0
1 3
0 2

Since $1\ \mathrm{xor}\ 0 = 1,\ 1\ \mathrm{xor}\ 3 = 2,\ 0\ \mathrm{xor}\ 2 = 2$, we can make those N1N - 1 warp gates, and they allow travel between every two planets, so this output will be considered correct. There are many other possible outputs that will also be considered correct.

8 0
1 0
1 3
1 5
6 7
6 4
6 2
3 2
8 7
1 2 3 4 5 6 7
-1