#P6651. 「SWTR-5」Chain

    ID: 7028 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DPO2优化拓扑排序容斥原理

「SWTR-5」Chain

Problem Description

You are given a directed acyclic graph (DAG) with nn vertices and mm edges. The graph is not guaranteed to be connected.

There are qq queries. In each query, you are given kk and kk pairwise distinct numbers cic_i. You need to compute: if these kk vertices are removed, how many chains will remain in the whole DAG. The answer should be taken modulo 109+710^9+7. Each query is independent.

  • Definition of a “chain”: Suppose a chain of length pp has the path w0w1wp1wpw_0\to w_1\to\cdots\to w_{p-1}\to w_p. It should satisfy that w0w_0 has indegree 00 and wpw_p has outdegree 00. You can think of it as a food chain.

  • Two chains are “different” if and only if they have different lengths, or the sets of vertices they pass through are different.

  • Note carefully that chains newly created after deleting some vertices are not counted in the answer. For example, in the graph 12341\to 2\to 3\to 4, there is 11 chain 12341\to 2\to 3\to 4. If vertex 22 is removed, then 00 chains remain.

Input Format

The first line contains two integers n,mn,m, representing the number of vertices and the number of edges.

The next mm lines each contain two integers u,v(uv)u,v(u\neq v), meaning there is a directed edge uvu\to v.

Line m+2m+2 contains an integer qq, representing the number of queries.

The next qq lines:

  • Each line first contains an integer kk, representing the number of vertices to remove.
  • Then follow kk integers cic_i, representing the indices of the vertices to remove.

Output Format

Output qq lines. Each line is the answer for that query modulo 109+710^9+7.

7 14
3 2
4 5
2 5
2 6
3 1
3 5
3 7
3 6
6 4
1 4
6 5
1 6
7 2
7 4
7
3 2 4 6
2 4 6
2 2 5
2 1 4
0
1 4
1 6
1
3
0
6
13
7
5
233 1
1 2
6
0
1 10
2 10 40
1 1
1 2
2 1 2
232
231
230
231
231
231

Hint

"Sample 1 Explanation"

The DAG is shown in the figure:

Query 11: If 2,4,62,4,6 are removed, then 11 chain remains: 353\to 5.

Query 22: If 4,64,6 are removed, then 33 chains remain: 353\to 5, 3253\to 2\to 5, 37253\to 7\to 2\to 5.

Query 77: If 66 is removed, then 55 chains remain: 353\to 5, 3253\to 2\to 5, 37253\to 7\to 2\to 5, 31453\to 1\to 4\to 5, 37453\to 7\to 4\to 5.

"Constraints and Notes"

This problem uses bundled testdata.

  • Subtask 1 (1 point): The given graph is a single chain.
  • Subtask 2 (14 points): n,q10n,q\leq 10.
  • Subtask 3 (20 points): q103q\leq 10^3.
  • Subtask 4 (17 points): k=1k=1.
  • Subtask 5 (18 points): k=2k=2.
  • Subtask 6 (30 points): No special restrictions.

For 100%100\% of the testdata: 2n2×1032\leq n\leq 2\times 10^3, $1\leq m\leq \min(\frac{n\times(n-1)}{2},2\times 10^4)$, 1q5×1051\leq q\leq 5\times 10^5.
All queries satisfy: 1k2×1061\leq \sum k\leq 2\times 10^6, 0kmin(n,15)0\leq k\leq \min(n,15), 1cin1\leq c_i\leq n. It is guaranteed that all cic_i are pairwise distinct.

This problem is slightly time-tight, so please pay attention to IO optimization.


"Source"

Sweet Round 05 D.
Idea & solution: Alex_Wei.

Translated by ChatGPT 5