当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6864:Jumping on a Cactus

题目描述
It is preferrable to read the pdf statment.

Cuber QQ has recently learned jumping on graphs. He now wants to demonstrate his skills on a cactus.

Recall that, cactus refers to a graph with every edge appearing in at most one cycle. If you do not know what a cycle is, formally, a cycle of length $k$ denotes an edge sequence $(u_1,u_2), (u_2,u_3),\ldots,(u_{k-1},u_k),(u_k,u_1)$.

Assuming you are given an undirected cactus $G=(V, E)$, with $n$ vertices and $m$ edges. A jumping on the cactus can be thought of as a visit to all vertices where every vertex is visited exactly once. That can be represented with a permutation of $1$ to $n$, $p_1, p_2, \ldots, p_n$, and they are visited in order.

Cuber QQ also wishes his jumping to be gradually approaching or distancing away from a particular node $e$. Concretely, we define $d(a, b)$ to be the distance from $a$ to $b$ (the minimum edges needs to be passed through from $a$ to $b$). A jumping is defined to be monotonic if,


  • for all edges $(u, v) \in E$, $d(u, e) < d(v, e)$ when $u$ is visited before $v$, or,

  • for all edges $(u, v) \in E$, $d(u, e) > d(v, e)$ when $u$ is visited after $v$.



Count the number of different monotonic jumping plans. Since the answer can be very large, you should print the answer modulo $998~244~353$.
输入解释
The first line of the input contains a single integer $T$ ($1\le T\le 30$), denoting the number of test cases.

For each of the next $T$ cases:


  • The first line contains three space-separated integers $n$, $m$, $e$ ($2\le n\le 5~000$, $1\le m\le 2(n-1)$, $1\le e\le n$).

  • The $i$-th of the next $m$ lines contains two space-separated integers $u_i$, $v_i$ ($1\le u_i,v_i\le n$, $u_i\ne v_i$). It is guaranteed that $d(u_i, e) \ne d(v_i, e)$.



There are at most $10$ test cases where $n\ge 1~000$.
输出解释
For each test case, output one line contains one integer denoting the answer modulo $998~244~353$.

Notes


For the example, $G$ looks like:



$3$ is the index of reference vertex.

There are $8$ correct permutations:


  • $\{ 3,2,4,1,6,5 \}$.

  • $\{ 3,2,1,4,6,5 \}$.

  • $\{ 3,2,1,6,4,5 \}$.

  • $\{ 3,2,1,6,5,4 \}$.

  • $\{ 3,2,4,6,1,5 \}$.

  • $\{ 3,2,6,4,1,5 \}$.

  • $\{ 3,2,6,1,4,5 \}$.

  • $\{ 3,2,6,1,5,4 \}$.

输入样例
1
6 7 3
6 2
5 6
1 5
1 2
3 2
3 2
4 2
输出样例
8
来自杭电HDUOJ的附加信息
Recommend IceyWang

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6864

最后修改于 2020-10-25T23:35:02+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/2000MS(Java/Others) 524288/524288K(Java/Others)