#P4382. [八省联考 2018] 劈配

    ID: 3340 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2018各省省选网络流O2优化枚举,暴力图的建立,建图

[八省联考 2018] 劈配

Description

Skilled as usual, Zayid smoothly passed the open auditions. The next stage is the mentors' blind selection, with rules as follows:

There are nn contestants in total (numbered from 11 to nn). Each writes a piece of code and presents their dream. Then all mentors rank these contestants. To avoid future trouble, it is required that there are no ties in the rankings.

At the same time, each contestant independently fills out a preference form to evaluate the mm mentors (numbered from 11 to mm). The form contains mm preference tiers. For each tier, the contestant may list at most CC mentors, and each mentor may be listed at most once by each contestant (skipping some mentors is allowed).

After both sides finish, admissions are carried out. Each mentor has an upper bound on their team size, which means some contestants' higher preferences, or even all their preferences, may not be met. The show defines "the result for the top ii contestants is optimal" as follows:

  • The result for the top 11 contestant is optimal if and only if contestant 11 is admitted to their highest nonempty preference (in particular, if contestant 11 did not submit a preference form, then this contestant is eliminated).

  • The result for the top ii contestants is optimal if and only if, given that the result for the top i1i - 1 contestants is optimal, contestant ii is admitted to the highest preference that is theoretically possible (in particular, if contestant ii did not submit a preference form, or if all mentors in their preferences are already full, then this contestant is eliminated).

If a scheme satisfies "the result for the top nn contestants is optimal," we simply call this scheme optimal.

For example, there are 22 mentors, Teacher T\rm T and Teacher F\rm F, each with a team size cap of 11; there are 22 contestants, Zayid and DuckD, ranked 11 and 22, respectively. Then the following 33 preference forms and their corresponding optimal admission results are as shown in the tables:

It can be proved that, for the above preference forms, the corresponding schemes are the unique optimal admission results.

Everyone has an ideal value sis_i, meaning that contestant ii hopes to be admitted to their sis_i-th or better preference; otherwise, they will be very disappointed.

Now all contestants' preference forms and rankings have been published. Coincidentally, each contestant's ranking exactly matches their ID.

For each contestant, Zayid wants to know the answers to the following two questions:

  • In the optimal admission scheme, to which preference tier will they be admitted?

  • With other contestants' relative order unchanged, by at least how many ranks must they climb so that they are not disappointed?

As a top-notch coder on "China's New Code," Zayid certainly solved this problem easily. But he still wants you to compute it again to verify his result.

Input Format

Each test point contains multiple testcases. The first line contains 22 non-negative integers T,CT, C separated by a space, representing the number of testcases and the maximum number of mentors allowed per preference tier, respectively.

Then for each testcase:

  • The first line contains two positive integers n,mn, m separated by a space.

n,mn, m denote the number of contestants and the number of mentors, respectively.

  • The second line contains mm positive integers separated by spaces: the ii-th integer is bib_i.

bib_i is the team size upper bound of mentor ii.

Lines 33 to n+2n + 2 each contain mm non-negative integers: in line i+2i + 2, the jj-th number from the left is ai,ja_{i,j}.

ai,ja_{i,j} means contestant ii placed mentor jj as their ai,ja_{i,j}-th preference. In particular, if ai,j=0a_{i,j} = 0, it means this contestant did not include this mentor on the form.

In this part, it is guaranteed that within each row no positive number appears more than CC times (00 may appear more than CC times), and all ai,jma_{i,j} \leqslant m.

  • Line n+3n + 3 contains nn positive integers separated by spaces, where the ii-th integer is sis_i.

sis_i is the ideal value of contestant ii.

In this part, it is guaranteed that sims_i \leqslant m.

Output Format

Output the answers for each testcase in order. For each testcase, output 22 lines:

  • The first line contains nn positive integers separated by spaces. The ii-th integer means:

    the preference tier to which contestant ii will be admitted in the optimal scheme.

In particular, if this contestant is eliminated, this number is m+1m + 1.

  • The second line contains nn non-negative integers separated by spaces. The ii-th integer means:

    the minimum number of ranks contestant ii must climb so as not to be disappointed.

In particular, if this contestant will certainly be disappointed, this number is ii.

3 5
2 2
1 1
2 2
1 2
1 1
2 2
1 1
1 2
1 2
2 1
2 2
1 1
0 1
0 1
2 2
2 1
1 0
1 2
0 1
1 3
0 1
1 5
4 3
2 1 1
3 1 3
0 0 1
3 1 2
2 3 1
2 3 3 3
1 1 3 2
0 0 0 0

Hint

  • Explanation for Sample 11:

The three datasets correspond to the three tables in the Description.

For the first dataset: because contestant 11 did not list any first preference, they definitely cannot be admitted to their first preference tier and will definitely be disappointed. Contestant 22 is not disappointed with the original ranking, so they do not need to improve their rank.

For the second and third datasets: contestant 11 does not need to improve their rank. Aiming for first preference, contestant 22 must rise to rank 11 to get their wish.

  • Explanation for Sample 22:

Contestant 11 listed only mentor 22 as first preference, so contestant 11 must be admitted by mentor 22.

Contestant 22 listed only mentor 33 as first preference, so contestant 22 must be admitted by mentor 33.

Since mentors 22 and 33 are full, and contestants 33 and 44 both listed mentor 11, they will both be admitted by mentor 11.

Therefore, contestants 11 and 22 are both admitted to their 11-st preference, contestant 33 is admitted to their 33-rd preference, and contestant 44 is admitted to their 22-nd preference.

Since they all get what they want, none of them needs to improve their rank.

Test point ID nn \leqslant mm \leqslant CC Other conditions
1 1010 11 =1=1 None
2 22 =2=2 si=ms_i = m
3 33 =3=3 None
4 100100 =1=1 bi=1b_i = 1
5 None
6 200200 bi=1b_i = 1
7 None
8 100100 =10=10
9 200200 bi=1b_i = 1
10 None
  • For all test points, it is guaranteed that T5T \leqslant 5.

  • Across all data of all test points, it is guaranteed that mn200,binm \leqslant n \leqslant 200, b_i \leqslant n.

Translated by ChatGPT 5