Codeforces Round 440 (Div. 1, based on Technocup 2018 Elimination Round 2)
E
Restore the Tree
Codeforces
2900
原题
← D→
翻译中…

Petya had a tree consisting of $*n*$ vertices numbered with integers from $1$ to $*n*$. Accidentally he lost his tree.

翻译中…

Petya remembers information about $*k*$ vertices: distances from each of them to each of the $*n*$ tree vertices.

翻译中…

Your task is to restore any tree that satisfies the information that Petya remembers or report that such tree doesn't exist.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$ and $*k*$ ($2 ≤ *n* ≤ 30 000$, $1 ≤ *k* ≤ *min*(200, *n*)$) — the number of vertices in the tree and the number of vertices about which Petya remembers distance information.

翻译中…

The following $*k*$ lines contain remembered information. The $*i*$-th line contains $*n*$ integers $*d*_{*i*, 1}, *d*_{*i*, 2}, ..., *d*_{*i*, *n*}$ ($0 ≤ *d*_{*i*, *j*} ≤ *n* - 1$), where $*d*_{*i*, *j*}$ — the distance to $*j*$-th vertex from the $*i*$-th vertex that Petya remembers.

翻译中…

Output

翻译中…

If there are no suitable trees, print -1.

翻译中…

In the other case, print $*n* - 1$ lines: each line should contain two vertices connected by edge in the required tree. You can print edges and vertices in an edge in any order. The tree vertices are enumerated from $1$ to $*n*$.

翻译中…

If there are many solutions print any of them.

翻译中…

Note

翻译中…

Picture for the first sample:

翻译中…

image

翻译中…

样例

Input #1
5 2
0 1 2 3 2
2 1 0 1 2
Output #1
2 1
3 2
4 3
5 2
InputCopy OutputCopy
Input #2
3 1
1 2 1
Output #2
-1
InputCopy OutputCopy
题目信息
题号
871E
时间限制
3 s
内存限制
256 MB
标签
图论
贪心
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。