Codeforces Round 1111 (Div. 2)
E
构造一棵树
Build a Tree
Codeforces
2300
原题
← D2F →

构造一棵树AI (CI翻译)

You are given two integers $n$ and $k$.

翻译中…

Construct a tree$^{\text{∗}}$ with $n$ vertices such that $\sum\limits_{i = 1}^{n} \operatorname{dist}(i, (i \bmod n) + 1) = k$$^{\text{†}}$, or determine that no such tree exists.

翻译中…

$^{\text{∗}}$A tree is a connected graph without cycles.$^{\text{†}}$$\operatorname{dist}(i, j)$ is the number of edges on the shortest path from vertex $i$ to vertex $j$ in the tree.

翻译中…

Input

输入格式

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

每个测试包含多组测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)

The only line of each test case contains two integers $n$ and $k$ ($2 \le n \le 2 \cdot 10^5$, $0 \le k \le n^2$) — the number of vertices in the tree and the required value of $k$.

每个测试用例仅包含一行,包含两个整数 $n$ 和 $k$($2 \le n \le 2 \cdot 10^5$,$0 \le k \le n^2$)——树的顶点数以及所需的 $k$ 值。AI (CI翻译)

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

保证所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, if there is no solution, output $-1$.

对于每个测试用例,如果不存在解,输出 $-1$。AI (CI翻译)

Otherwise, output $n - 1$ lines. Each line should contain two integers $u$ and $v$ ($1 \le u, v \le n$), denoting an edge of the tree. The edges may be output in any order.

否则,输出 $n - 1$ 行。每行应包含两个整数 $u$ 和 $v$($1 \le u, v \le n$),表示树中的一条边。边可以按任意顺序输出。AI (CI翻译)

If there are multiple suitable trees, output any of them.

如果有多个符合条件的树,输出其中任意一棵即可。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first example, the tree consists of the single edge $(1, 2)$. Therefore, $\operatorname{dist}(1, 2) + \operatorname{dist}(2, 1) = 1 + 1 = 2$.

在第一个样例中,树由单条边 $(1, 2)$ 构成。因此,$\operatorname{dist}(1, 2) + \operatorname{dist}(2, 1) = 1 + 1 = 2$。AI (CI翻译)

In the second example, one possible tree is shown below.

在第二个样例中,一棵可能的树如下图所示。AI (CI翻译)

image

imageAI (CI翻译)

For this tree, $\operatorname{dist}(1, 2) + \operatorname{dist}(2, 3) + \operatorname{dist}(3, 4) + \operatorname{dist}(4, 1) = 1 + 2 + 2 + 1 = 6$.

对于这棵树,$\operatorname{dist}(1, 2) + \operatorname{dist}(2, 3) + \operatorname{dist}(3, 4) + \operatorname{dist}(4, 1) = 1 + 2 + 2 + 1 = 6$。AI (CI翻译)

In the fourth example, it can be shown that no suitable tree exists.

在第四个样例中,可以证明不存在符合条件的树。 AI (CI翻译)

样例

Input #1
5
2 2
4 6
5 10
5 14
100 8347
Output #1
1 2
1 4
1 3
1 2
3 2
3 4
4 1
5 3
-1
-1
InputCopy OutputCopy
题目信息
题号
2247E
时间限制
2 s
内存限制
256 MB
标签
构造
树
双指针

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