CF757C.Felicity is Coming!

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has g__i Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in the fest which claims to evolve any Pokemon. The type of a Pokemon could change after evolving, subject to the constraint that if two Pokemon have the same type before evolving, they will have the same type after evolving. Also, if two Pokemon have different types before evolving, they will have different types after evolving. It is also possible that a Pokemon has the same type before and after evolving.

Formally, an evolution plan is a permutation f of {1, 2, ..., m}, such that f(x) = y means that a Pokemon of type x evolves into a Pokemon of type y.

The gym leaders are intrigued by the special evolution camp and all of them plan to evolve their Pokemons. The protocol of the mountain states that in each gym, for every type of Pokemon, the number of Pokemon of that type before evolving any Pokemon should be equal the number of Pokemon of that type after evolving all the Pokemons according to the evolution plan. They now want to find out how many distinct evolution plans exist which satisfy the protocol.

Two evolution plans _f_1 and _f_2 are distinct, if they have at least one Pokemon type evolving into a different Pokemon type in the two plans, i. e. there exists an i such that _f_1(i) ≠ _f_2(i).

Your task is to find how many distinct evolution plans are possible such that if all Pokemon in all the gyms are evolved, the number of Pokemon of each type in each of the gyms remains the same. As the answer can be large, output it modulo 109 + 7.

又到了一年中的这个时候,福利西蒂节(Felicity)即将到来,你可以在整个喜马拉雅地区看到人们欢庆的场景。喜马拉雅地区共有 nn 座道馆。第 ii 座道馆中有 gig_i 只宝可梦。喜马拉雅地区共有 mm 种互不相同的宝可梦种类,编号从 11 到 mm。节日期间特别设立了一个进化营地,声称可以进化任意宝可梦。宝可梦的种类在进化后可能发生变化,但需满足如下约束:若两只宝可梦在进化前属于同一类型,则它们在进化后也必须属于同一类型;若两只宝可梦在进化前属于不同类型,则它们在进化后也必须属于不同类型。此外,一只宝可梦在进化前后也可能保持相同类型。

形式化地,一个进化方案是一个集合 {1, 2, …, m}\{1,\,2,\,\dots,\,m\} 上的置换 ff,其中 f(x)=yf(x) = y 表示类型为 xx 的宝可梦将进化为类型为 yy 的宝可梦。

各道馆馆主对这一特殊的进化营地颇感兴趣,因此均计划对其道馆内的所有宝可梦进行进化。根据山区协议,在每座道馆中,对于每一种宝可梦类型,进化前该类型的宝可梦数量必须等于按该进化方案完成全部进化后该类型的宝可梦数量。现在他们希望知道:有多少种互不相同的进化方案满足该协议?

两个进化方案 f1f_1 和 f2f_2 被视为不同,当且仅当存在至少一个宝可梦类型 ii,使得 f1(i)≠f2(i)f_1(i) \ne f_2(i)。

你的任务是计算满足以下条件的互不相同的进化方案总数:当所有道馆中的所有宝可梦均按该方案进化后,每座道馆中每种宝可梦类型的数量均保持不变。由于答案可能很大,请输出其对 109+710^9 + 7 取模的结果。

输入格式

The first line contains two integers n and m (1 ≤ n ≤ 105, 1 ≤ m ≤ 106) — the number of gyms and the number of Pokemon types.

The next n lines contain the description of Pokemons in the gyms. The i-th of these lines begins with the integer g__i (1 ≤ g__i ≤ 105) — the number of Pokemon in the i-th gym. After that g__i integers follow, denoting types of the Pokemons in the i-th gym. Each of these integers is between 1 and m.

The total number of Pokemons (the sum of all g__i) does not exceed 5·105.

第一行包含两个整数 nn 和 mm(1≤n≤1051 \leq n \leq 10^5,1≤m≤1061 \leq m \leq 10^6)——分别表示道馆的数量和宝可梦种类的数量。

接下来的 nn 行描述了各道馆中的宝可梦。其中第 ii 行以整数 gig_i(1≤gi≤1051 \leq g_i \leq 10^5)开头,表示第 ii 个道馆中宝可梦的数量;随后是 gig_i 个整数,表示该道馆中各宝可梦的种类。每个整数均在 11 到 mm 之间。

宝可梦总数(即所有 gig_i 的总和)不超过 5⋅1055 \cdot 10^5。

输出格式

Output the number of valid evolution plans modulo 109 + 7.

输出合法进化方案的数量对 109+710^9 + 7 取模的结果。

输入输出样例

  • 输入#1

    2 3
    2 1 2
    2 2 3

    输出#1

    1
  • 输入#2

    1 3
    3 1 2 3

    输出#2

    6
  • 输入#3

    2 4
    2 1 2
    3 2 3 4

    输出#3

    2
  • 输入#4

    2 2
    3 2 2 1
    2 1 2

    输出#4

    1
  • 输入#5

    3 7
    2 1 2
    2 3 4
    3 5 6 7

    输出#5

    24

说明/提示

In the first case, the only possible evolution plan is:

In the second case, any permutation of (1,  2,  3) is valid.

In the third case, there are two possible plans:

In the fourth case, the only possible evolution plan is:

第一种情况下,唯一可能的进化方案是:

第二种情况下,(1,  2,  3) 的任意一个排列均有效。

第三种情况下,存在两种可能的方案:

第四种情况下,唯一可能的进化方案是:

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

首页