P28060 [洛谷] [JOISC 2024 Day4] Table Tennis
提高+
题目描述

Problem Description

In the Kingdom of JOI, a table tennis tournament is held. $N$ beavers, numbered from $1$ to $N$, participate in this tournament and play a round-robin match.

You have obtained the following information about the results of the matches from Bitaro:

  • There are no draws.
  • Exactly $M$ ways exist to choose $3$ beavers to form a "trilemma". Note that $3$ beavers $i, j, k$ ($1 \leq i < j < k \leq N$) form a "trilemma" if and only if one of the following two conditions is exactly met:
  • Beaver $i$ defeats beaver $j$, beaver $j$ defeats beaver $k$, and beaver $k$ defeats beaver $i$.
  • Beaver $i$ defeats beaver $k$, beaver $k$ defeats beaver $j$, and beaver $j$ defeats beaver $i$.

You are unsure if the information provided by Bitaro is correct, so you decide to consider whether there is any match result that matches the information provided by Bitaro. Write a program that, based on the information provided by Bitaro, determines if there is any match result that matches the information, and if so, finds any one such result.

Input Format

A test case includes $Q$ scenarios, numbered from $1$ to $Q$. Each scenario specifies the following values:

  • The number of beavers participating in the tournament, $N$.
  • The number of ways to choose $3$ beavers to form a "trilemma", $M$.

The format of the input data is as follows:

  • $Q$

The input data for each scenario is as follows:

  • $N$ $M$

Output Format

For each scenario, write the answer to the standard output in the following order:

In some scenarios, if there is any match result that matches the information, output it in the following way:

  • Yes
  • $S_2$
  • $S_3$
  • ...
  • $S_N$

Here, $S_i$ ($2 \leq i \leq N$) is a string of length $i-1$ consisting of '0' or '1'. The $j$-th character of $S_i$ is '0' if beaver $i$ is defeated by beaver $j$, and '1' if beaver $i$ defeats beaver $j$. If there are multiple results, you may output any one of them.

In some scenarios, if there is no match result that matches the information, output No.

Sample Input and Output

Sample Input #1

2
3 1
4 4

Sample Output #1

Yes
0
10
No

Sample Input #2

1
5 3

Sample Output #2

Yes
0
11
001
0101

Notes

Sample Explanation 1

There are $Q = 2$ scenarios.

In the output for scenario $1$, beaver $1$ defeats beaver $2$, beaver $2$ defeats beaver $3$, and beaver $3$ defeats beaver $1$. Thus, beavers $1, 2, 3$ form a "trilemma". There are no other ways to choose $3$ beavers, so there is exactly $1$ way to choose $3$ beavers to form a "trilemma".

Another output for scenario $1$ is as follows:

Yes
1
01

In scenario $2$, there is no match result that matches the information. Therefore, output No.

This sample input satisfies the constraints of subtasks $2, 3, 4, 5, 6$.

Sample Explanation 2

In the output for scenario $1$, beaver $1$ defeats beaver $4$, beaver $4$ defeats beaver $3$, and beaver $3$ defeats beaver $1$. Thus, beavers $1, 3, 4$ form a "trilemma". There are two other ways to choose $3$ beavers to form a "trilemma": choosing beavers $2, 3, 4$ and choosing beavers $3, 4, 5$. Therefore, there are exactly $3$ ways to choose $3$ beavers to form a "trilemma".

This sample input satisfies the constraints of all subtasks.

Constraints

  • $1 \leq Q$.
  • $3 \leq N \leq 5000$.
  • $0 \leq M \leq \frac{1}{6} N(N - 1)(N - 2)$.
  • The sum of $N$ over all $Q$ scenarios does not exceed 5000.
  • All given values are integers.

Subtasks

  1. (5 points) $M \leq N - 2$.
  2. (4 points) The sum of $N$ over all $Q$ scenarios does not exceed 7.
  3. (23 points) The sum of $N$ over all $Q$ scenarios does not exceed 20.
  4. (30 points) The sum of $N$ over all $Q$ scenarios does not exceed 150.
  5. (15 points) The sum of $N$ over all $Q$ scenarios does not exceed 600.
  6. (23 points) No additional constraints.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 3 1 4 4
样例输出
Yes 0 10 No