#P10441. [JOIST 2024] 乒乓球 / Table Tennis

[JOIST 2024] 乒乓球 / Table Tennis

Problem Description

A table tennis tournament was held in the kingdom of JOI. NN beavers numbered from 11 to NN participated in the tournament, and they played a round-robin tournament.

You learned the following information about the match results from Bitaro.

  • There are no drawn matches.
  • There are exactly MM ways to choose 33 beavers that form a “triple paradox”. Note that 33 beavers i,j,ki, j, k (1i<j<kN1 \leq i < j < k \leq N) form a “triple paradox” if and only if exactly one of the following two conditions holds.
    • Beaver ii defeated beaver jj, beaver jj defeated beaver kk, and beaver kk defeated beaver ii.
    • Beaver ii defeated beaver kk, beaver kk defeated beaver jj, and beaver jj defeated beaver ii.

You are not sure whether the information provided by Bitaro is correct, so you decided to think about whether there are any match results consistent with Bitaro’s information. Write a program that, based on the information provided by Bitaro, determines whether there are any match results consistent with it; if there are, find any such match results.

Input Format

One test case consists of QQ scenarios, numbered from 11 to QQ. Each scenario specifies the following values.

  • The number of beavers NN participating in the tournament.
  • The number of ways MM to choose 33 beavers that form a “triple paradox”.

The input format is as follows.

  • QQ

For each scenario, the input format is as follows.

  • NN MM

Output Format

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

In some scenarios, if there exist any match results consistent with the information, output in the following format.

  • Yes
  • S2S_2
  • S3S_3
  • ...
  • SNS_N

Here, for SiS_i (2iN2 \leq i \leq N), it is a string of length i1i - 1 consisting of characters '0' and '1'. The jj-th character of SiS_i is '0' if beaver ii was defeated by beaver jj, and '1' if beaver ii defeated beaver jj. If multiple results exist, you may output any one of them.

In some scenarios, if there are no match results consistent with the information, output No.

2
3 1
4 4
Yes
0
10
No
1
5 3
Yes
0
11
001
0101

Hint

Sample Explanation 1

There are Q=2Q = 2 scenarios.

In this sample output, for scenario 11, the result is: beaver 11 defeated beaver 22, beaver 22 defeated beaver 33, and beaver 33 defeated beaver 11. Therefore, beavers 1,2,31, 2, 3 form a “triple paradox”. There is no other way to choose 33 beavers, so there are exactly 11 way to choose 33 beavers that form a “triple paradox”.

Another possible output for scenario 11 is as follows.

Yes
1
01

In scenario 22, there are no match results consistent with the information. Therefore, output No.

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

Sample Explanation 2

In this sample output, for scenario 11, the result is: beaver 11 defeated beaver 44, beaver 44 defeated beaver 33, and beaver 33 defeated beaver 11. Therefore, beavers 1,3,41,3,4 form a “triple paradox”. There are two other ways to choose 33 beavers that form a “triple paradox”: choosing beavers 2,3,42,3,4 and choosing beavers 3,4,53,4,5. Therefore, there are exactly 33 ways to choose 33 beavers that form a “triple paradox”.

This sample input satisfies the constraints of all subtasks.

Constraints

  • 1Q1 \leq Q.
  • 3N50003 \leq N \leq 5000.
  • 0M16N(N1)(N2)0 \leq M \leq \frac{1}{6} N(N - 1)(N - 2).
  • The sum of NN over the QQ scenarios does not exceed 5000.
  • All given values are integers.

Subtasks

  1. (5 points) MN2M \leq N - 2.
  2. (4 points) The sum of NN over the QQ scenarios does not exceed 7.
  3. (23 points) The sum of NN over the QQ scenarios does not exceed 20.
  4. (30 points) The sum of NN over the QQ scenarios does not exceed 150.
  5. (15 points) The sum of NN over the QQ scenarios does not exceed 600.
  6. (23 points) No additional constraints.

Translated by ChatGPT 5