QOJ.ac

QOJ

Límite de tiempo: 3 s Límite de memoria: 1024 MB Puntuación total: 100 Dificultad: [mostrar] Hackeable ✓

#22236. 幸福指数

Estadísticas

虚像所在的社交圈共有 $n$ 个人。有 $m$ 对形如 $u$ 喜欢 $v$ 的关系。注意,$u$ 可能等于 $v$,但是同一条关系一定不会多次出现。

第 $i$ 个人有一个魅力值 $a_i$。定义一个人的幸福指数为喜欢他的所有人的魅力值之和。而整个社交圈的幸福指数为所有人幸福指数的乘积。

不幸的是,由于 OI 导致的高压环境,每个人的魅力值都会波动。对于第 $i$ 个人,他可能得魅力值有 $b_i$ 种:$c_{i,1},c_{i,2},\dots,c_{i,b_i}$。其实际魅力值 $a_i$ 会在序列 $c_i$ 中随机选择。

虚像想要知道整个社交圈的幸福指数的期望,对 $\mathrm{mod}$ 取模。保证 $b_i$ 在模 $\mathrm{mod}$ 意义下可逆。

输入格式

第一行三个正整数 $\mathrm{mod},n,m$。

接下来 $m$ 行,每行两个正整数,表示一条喜欢关系 $(u,v)$。保证不存在重复的 $(u,v)$ 二元组。

接下来 $n$ 行,每行的第一个正整数表示 $b_i$,接下来 $b_i$ 个非负整数表示 $c_{i,j}$。保证 $b_i$ 在模 $\mathrm{mod}$ 意义下可逆。

输出格式

一行,一个非负整数,表示期望对 $\mathrm{mod}$ 取模后的值。

样例

样例 1

输入
998244353 2 3
1 1
1 2
2 2
2 6 11
2 3 7
输出
121
解释

两个人的魅力值共有 $4$ 种可能,分别为 $(6,3)$,$(6,7)$,$(11,3)$,$(11,7)$,各有 $\frac{1}{4}$ 的概率出现。

因此,整个社交圈的幸福指数期望为 $\frac{1}{4}(6\times(6+3)+6\times(6+7)+11\times(11+3)+11\times(11+7))=121$。

样例 2

输入
123456789 3 2
2 3
3 2
1 0
1 7
2 2 1
输出
0
解释

没有人喜欢虚像(第一个人),因此他的幸福指数一定是 $0$。容易发现此时整个社交圈的幸福指数也一定是 $0$。

数据范围

  • $10^8\leq \mathrm{mod}\leq10^9+7$;
  • $1\leq n\leq21$;
  • $1\leq m\leq n^2$;
  • $1\leq u,v\leq n$;
  • $1\leq b_i\leq100$;
  • $0\leq c_{i,j} < \mathrm{mod}$;
  • 对于 $1\leq i\leq n$,$1\leq j< k\leq b_i$,有 $c_{i,j}\neq c_{i,k}$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.