Codeforces Round 1023 (Div. 2)
E
Ain and Apple Tree
Codeforces
2600
原题
← DF1 →
翻译中…

If I was also hit by an apple falling from an apple tree, could I become as good at physics as Newton?

翻译中…

To be better at physics, Ain wants to build an apple tree so that she can get hit by apples on it. Her apple tree has $n$ nodes and is rooted at $1$. She defines the weight of an apple tree as $\sum \limits_{i=1}^n \sum \limits_{j=i+1}^n \text{dep}(\operatorname{lca}(i,j))$.

翻译中…

Here, $\text{dep}(x)$ is defined as the number of edges on the unique shortest path from node $1$ to node $x$. $\operatorname{lca}(i, j)$ is defined as the unique node $x$ with the largest value of $\text{dep}(x)$ and which is present on both the paths $(1, i)$ and $(1, j)$.

翻译中…

From some old books Ain reads, she knows that Newton's apple tree's weight is around $k$, but the exact value of it is lost.

翻译中…

As Ain's friend, you want to build an apple tree with $n$ nodes for her, and the absolute difference between your tree's weight and $k$ should be at most $1$, i.e. $|\text{weight} - k| \le 1$. Unfortunately, this is not always possible, in this case please report it.

翻译中…

Input

翻译中…

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.

翻译中…

The first line of each test case contains two numbers $n,k$ ($2 \le n \le 10^5,0 \le k \le 10^{15}$).

翻译中…

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

翻译中…

Output

翻译中…

For each test case, first output $\texttt{Yes}$ if a solution exists or $\texttt{No}$ if no solution exists. You may print each character in either case, for example $\texttt{YES}$ and $\texttt{yEs}$ will also be accepted.

翻译中…

If there's at least one solution, print $n-1$ lines and each line contains two numbers $u,v$ $(1 \le u,v \le n)$ represents the apple tree.

翻译中…

Note

翻译中…

In the first test case, we can check that the weight is $0$. This satisfies the condition because $k = 1$ and so the absolute difference is only $1$.

翻译中…

In the second test case, there exists no solution because there are no trees of $2$ nodes with weights of either $1, 2$ or $3$.

翻译中…

样例

Input #1
5
2 1
2 2
4 0
5 7
5 5
Output #1
Yes
1 2
No
Yes
1 2
1 3
1 4
Yes
1 3
3 5
4 5
3 2
Yes
1 2
2 3
2 4
2 5
InputCopy OutputCopy
题目信息
题号
2107E
时间限制
2 s
内存限制
256 MB
标签
二分
构造
贪心
数学
树

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