CF2174F.Mosaic Tree

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The master creates a composition of nn colored mosaic elements. Each element is painted in one of mm possible colors (the colors are numbered from 11 to mm).

The master arranges the composition in such a way that it can be represented as a tree.

The composition is considered beautiful if for each color ii, the total degree of all vertices of color ii has a specified parity maski\mathrm{mask}_i, where mask\mathrm{mask} is an array of mm numbers 00 or 11.

Help the master count the number of ways to create a beautiful composition. Output the answer modulo 109+710^9 + 7.

大师创作一幅由 nn 个彩色马赛克元素构成的作品。每个元素被涂上 mm 种可能颜色之一(颜色编号为 11 到 mm)。

大师将作品以树的形式进行排布。

若对每种颜色 ii,所有颜色为 ii 的顶点的度数总和具有指定的奇偶性 maski\mathrm{mask}_i,则该作品被称为“优美的”。其中 mask\mathrm{mask} 是一个长度为 mm 的数组,每个元素为 00 或 11。

请帮助大师计算创作一幅优美作品的方案数。答案对 109+710^9 + 7 取模。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). The description of the test cases follows.

The first line of each test case contains two integers nn and mm (1≤n,m≤1041 \le n, m \le 10^4) — the number of vertices and the number of possible colors, respectively.

The second line of each test case contains nn integers cic_i (1≤ci≤m1 \le c_i \le m) — the color of vertex ii.

The third line of each test case contains mm integers maski\mathrm{mask}_i (maski∈0,1\mathrm{mask}_i \in {0, 1}) — the parity of color ii (if the total degree of vertices of color ii should be even, maski=0\mathrm{mask}_i = 0, otherwise — maski=1\mathrm{mask}_i = 1).

It is guaranteed that the sum of the values of nn across all test cases does not exceed 10410^4, and it is also guaranteed that the sum of the values of mm across all test cases does not exceed 10410^4.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1001 \le t \le 100)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m≤1041 \le n, m \le 10^4)—— 分别表示顶点数量和可能的颜色数量。

每个测试用例的第二行包含 nn 个整数 cic_i(1≤ci≤m1 \le c_i \le m)—— 表示顶点 ii 的颜色。

每个测试用例的第三行包含 mm 个整数 maski\mathrm{mask}_i(maski∈{0,1}\mathrm{mask}_i \in \{0, 1\})—— 表示颜色 ii 的奇偶性(若颜色 ii 的所有顶点的总度数应为偶数,则 maski=0\mathrm{mask}_i = 0;否则 maski=1\mathrm{mask}_i = 1)。

保证所有测试用例中 nn 的总和不超过 10410^4,且所有测试用例中 mm 的总和也不超过 10410^4。

输出格式

For each test case, output a single integer on a separate line — the number of ways to create a beautiful composition modulo 109+710^9 + 7.

对于每个测试用例,在单独一行中输出一个整数——构造优美组合的方案数对 109+710^9 + 7 取模的结果。

输入输出样例

  • 输入#1

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

    输出#1

    8
    0
    125
    384
    0

说明/提示

In the first test case, a valid example of a tree would be described by the edges (1,2),(1,3),(1,4){(1, 2), (1, 3), (1, 4)}. Here, the degrees are 3,1,1,13, 1, 1, 1 respectively. Here, the total degree of vertices with colour 11 is 44 which is 00 mod 22, and similarly, the total degree of vertices with colour 22 is 22 which is also 00 mod 22, as required by the statement.

An example of an invalid tree would be described by the edges (1,2),(2,3),(3,4){(1, 2), (2, 3), (3, 4)} as vertices with colour 11 have degrees adding to 33, which is odd.

在第一个测试用例中,一棵合法的树的一个有效示例由边集 {(1,2),(1,3),(1,4)}\{(1, 2), (1, 3), (1, 4)\} 描述。此时各顶点的度数分别为 3,1,1,13, 1, 1, 1。其中,颜色为 11 的顶点的度数之和为 44,满足模 22 余 00;类似地,颜色为 22 的顶点的度数之和为 22,同样满足模 22 余 00,符合题意要求。

一个非法树的示例如下:其边集为 {(1,2),(2,3),(3,4)}\{(1, 2), (2, 3), (3, 4)\},此时颜色为 11 的顶点的度数之和为 33,是奇数,不满足要求。

输入解题思路,AI测评打分。不知道怎么写?

首页