QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 256 MB Total points: 100 Difficulty: [show]

#4794. Salaj

Statistics

给定两个整数 $V$ 和 $E$,如果存在一个包含 $V$ 个顶点和 $E$ 条边的有向图,以及一个长度为 $E$ 的排列 $P$,使得从一个包含 $V$ 个顶点的空图开始,按照排列 $P$ 给出的顺序添加边,对于所有的 $1 \le i \le E$,$A[i]$ 均为添加第 $P[i]$ 条边后图中强连通分量的数量,则称长度为 $E$ 的数组 $A$ 为一个有效的连通性历史数组(简称 CHA)。

例如,对于 $V = 3$ 和 $E = 3$: $A = [3, 3, 3]$ 是一个有效的 CHA,因为存在图 $\{(1, 2), (1, 3), (2, 3)\}$。无论选择何种加边顺序,该图始终有三个强连通分量。 $A = [3, 3, 1]$ 是一个有效的 CHA,因为存在图 $\{(1, 2), (2, 3), (3, 1)\}$。如果按照这个顺序添加边,在添加前两条边后,图有三个强连通分量,添加第三条边后,图有一个强连通分量。 $A = [3, 2, 1]$ 不是一个有效的 CHA,因为不存在一个包含三个顶点和三条边的图,以及一种加边顺序,使得每添加一条边后强连通分量的数量都减少。

注意,图中不允许包含自环或重边(但如果存在边 $(x, y)$,则也可能存在边 $(y, x)$)。

给定 $Q$ 次查询,每次查询包含一对整数 $(V, MAX)$。你的任务是对于每一对 $(V, E)$(其中 $1 \le E \le MAX$),计算有效 CHA 的数量。

输入格式

第一行包含一个整数 $Q$,表示查询的数量($Q \le 10$)。接下来的 $Q$ 行中,第 $i$ 行描述第 $i$ 次查询,包含三个整数 $V_i$、$MAX_i$ 和 $MOD_i$($1 \le V_i \le 50$,$1 \le MAX_i \le V \cdot (V - 1)$,$1 \le MOD_i \le 10^9$)。

输出格式

输出 $Q$ 行,每行对应一次查询。第 $i$ 行必须包含 $MAX_i$ 个整数,表示第 $i$ 次查询的答案,结果对 $MOD_i$ 取模。第 $i$ 行的第 $j$ 个整数表示对于 $(V_i, j)$ 这一对参数的有效 CHA 数量。

样例

输入 1

2
5 10 666013
6 9 10

输出 1

1 2 4 9 21 50 110 209 351 546
1 2 4 9 1 1 6 0 7

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.