#P14053. [SDCPC 2019] Median

[SDCPC 2019] Median

题目描述

Recall the definition of the median of nn elements where nn is odd: sort these elements and the median is the (n+1)2\frac{(n+1)}{2}-th largest element.

In this problem, the exact value of each element is not given, but mm relations between some pair of elements are given. The ii-th relation can be described as (ai,bi)(a_i, b_i), which indicates that the aia_i-th element is strictly larger than the bib_i-th element.

For all 1kn1 \le k \le n, is it possible to assign values to each element so that all the relations are satisfied and the kk-th element is the median of the nn elements?

输入格式

There are multiple test cases. The first line of the input contains an integer TT, indicating the number of test cases. For each test case:

The first line contains two integers nn and mm (1n<1001 \le n < 100, 1mn21 \le m \le n^2), indicating the number of elements and the number of relations. It's guaranteed that nn is odd.

For the following mm lines, the ii-th line contains two integers aia_i and bib_i, indicating that the aia_i-th element is strictly larger than the bib_i-th element. It guaranteed that for all 1i<jm1 \le i < j \le m, aiaja_i \ne a_j or bibjb_i \ne b_j.

It's guaranteed that the sum of nn of all test cases will not exceed 2×1032 \times 10^3.

输出格式

For each test case output one line containing one string of length nn. If it is possible to assign values to each element so that all the relations are satisfied and the ii-th element is the median, the ii-th character of the string should be 1, otherwise it should be 0.

2
5 4
1 2
3 2
2 4
2 5
3 2
1 1
2 3
01000
000

提示

For the first sample test case, as the 2nd element is smaller than the 1st and the 3rd elements and is larger than the 4th and the 5th elements, it's possible that the 2nd element is the median.

For the second sample test case, as the 1st element can't be larger than itself, it's impossible to assign values to the elements so that all the relations are satisfied.