#6416. [ICPC 2024 Hangzhou R] Japanese Bands
[ICPC 2024 Hangzhou R] Japanese Bands
[ICPC 2024 Hangzhou R] Japanese Bands
题目描述
Grammy is designing a new trading card game (TCG) based on her favorite Japanese music media franchise, $\textit{BanG Dream!}$. By her design, there are $n_1$ character cards and $n_2$ music cards in total. Now she needs to assign an integer between $1$ and $m$ (both inclusive) for each card, representing the magic power it contains.In every TCG game, there must be some certain combos that may cause extra damage. Grammy now is considering a special rule that relates to the value assigned to cards. Specifically, pairs of integers are chosen, satisfying . Grammy wants to make sure each of these value combos can be played in her game. Therefore, for each pair of integers , the assignment must meet at least one of the two following constraints:
- can be found on a character card and can be found on a music card.
- can be found on a music card and can be found on a character card.
Please help Grammy count the number of valid card-value assignments.
Let be the multi-set of the integers on the character card and be the multi-set of the integers on the music card. We say two assignments are different if their s are different or their s are different.
Recall that an integer can appear multiple times in a multi-set. We say two multi-sets and are different if there exists an integer such that the number of times appears in is not equal to that in .
输入格式
There are multiple test cases. The first line of the input contains an integer $T$ ($1 \le T \le 500$) indicating the number of test cases. For each test case:The first line contains four integers , , and (, , ).
For the following lines, the -th line contains two integers and ().
It's guaranteed that there are at most test cases satisfying .
输出格式
For each test case output one line containing one integer indicating the number of valid card-value assignments. As the answer may be large, output the answer modulo $(10^9 + 7)$.3
2 3 3 3
2 3
1 1
2 3
2 2 2 1
1 1
1 1 10 2
1 2
1 3
6
4
0
提示
For the first sample test case, the valid pairs of $(\mathbb{C}, \mathbb{M})$ are $(\{1, 2\}, \{1, 1, 3\})$, $(\{1, 2\}, \{1, 2, 3\})$, $(\{1, 2\}, \{1, 3, 3\})$, $(\{1, 3\}, \{1, 1, 2\})$, $(\{1, 3\}, \{1, 2, 2\})$ and $(\{1, 3\}, \{1, 2, 3\})$.For the second sample test case, the valid pairs of are , , and . 标签: P14196|2024|ICPC|杭州