102537: [AtCoder]ABC253 Ex - We Love Forest

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

We have a graph $G$ with $N$ vertices numbered $1$ through $N$ and $0$ edges. You are given sequences $u=(u_1,u_2,\ldots,u_M),v=(v_1,v_2,\ldots,v_M)$ of length $M$.

You will perform the following operation $(N-1)$ times.

  • Choose $i$ $(1 \leq i \leq M)$ uniformly at random. Add to $G$ an undirected edge connecting Vertices $u_i$ and $v_i$.

Note that the operation above will add a new edge connecting Vertices $u_i$ and $v_i$ even if $G$ already has one or more edges between them. In other words, the resulting $G$ may contain multiple edges.

For each $K=1,2,\ldots,N-1$, find the probability, modulo $998244353$, that $G$ is a forest after the $K$-th operation.

What is a forest?

An undirected graph without a cycle is called a forest. A forest is not necessarily connected.

Definition of probability modulo $998244353$

We can prove that the sought probability is always a rational number. Moreover, under the Constraints of this problem, it is guaranteed that, when the sought probability is represented by an irreducible fraction $\frac{y}{x}$, $x$ is indivisible by $998244353$.

Then, we can uniquely determine an integer $z$ between $0$ and $998244352$ (inclusive) such that $xz \equiv y \pmod{998244353}$. Print this $z$.

Constraints

  • $2 \leq N \leq 14$
  • $N-1 \leq M \leq 500$
  • $1 \leq u_i,v_i \leq N$
  • $u_i\neq v_i$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$ $M$
$u_1$ $v_1$
$\vdots$
$u_M$ $v_M$

Output

Print $N-1$ lines. The $i$-th line should contain the probability, modulo $998244353$, that $G$ is a forest after the $i$-th operation.


Sample Input 1

3 2
1 2
2 3

Sample Output 1

1
499122177

Let us denote by $(u, v)$ the edge connecting Vertices $u$ and $v$.

After the $1$-st operation, $G$ will have:

  • Edge $(1, 2)$ with a probability of $1/2$;
  • Edge $(2, 3)$ with a probability of $1/2$.

In both cases, $G$ is a forest, so the answer for $K=1$ is $1$.

After the $2$-nd operation, $G$ will have:

  • Edges $(1, 2)$ and $(1, 2)$ with a probability of $1/4$;
  • Edges $(2, 3)$ and $(2, 3)$ with a probability of $1/4$;
  • Edges $(1, 2)$ and $(2, 3)$ with a probability of $1/2$.

$G$ is a forest only when $G$ has Edges $(1, 2)$ and $(2, 3)$. Therefore, the sought probability is $1/2$; when represented modulo $998244353$, it is $499122177$, which should be printed.


Sample Input 2

4 5
1 2
1 2
1 4
2 3
2 4

Sample Output 2

1
758665709
918384805

Input

题意翻译

给定 $ n $ 个点无边的图,给定 $ m $ 条待选的无向边。每次等概率地从 $ m $ 条边中抽取一条边加入图中。 $ n - 1 $ 次询问求加 $ 1, 2, \cdots, n - 1 $ 次边后原图形成一个森林(一棵树亦为森林)的概率为多少。对 $ 998244353 $ 取模。

Output

得分:600分

问题描述

我们有一个顶点编号为1到N的图G,共有0条边。你将得到长度为M的序列u=(u1,u2,…,uM)和v=(v1,v2,…,vM)。

你需要执行(N-1)次以下操作:

  • 随机选择一个i(1≤i≤M)。在图G中添加连接顶点ui和vi的无向边。

注意,上述操作会在图G中添加连接顶点ui和vi的新边,即使图G已经有一条或多条边连接它们。也就是说,得到的G可能包含多条边。

对于每个K=1,2,…,N-1,找出图G在第K次操作后是森林的概率,结果对998244353取模。

什么是森林?

没有环的无向图被称为森林。森林不一定是连通的。

998244353取模概率的定义

我们可以证明所求概率总是有理数。此外,在本问题的约束下,可以保证当所求概率用不可约分数y/x表示时,x能被998244353整除。

然后,我们可以唯一确定一个0到998244352(包括)之间的整数z,使得xz≡y(mod 998244353)。打印这个z。

约束条件

  • 2≤N≤14
  • N-1≤M≤500
  • 1≤ui,vi≤N
  • ui≠vi
  • 输入中的所有值都是整数。

输入

输入通过标准输入给出以下格式:

$N$ $M$
$u_1$ $v_1$
$\vdots$
$u_M$ $v_M$

输出

打印N-1行。第i行应该包含图G在第i次操作后是森林的概率,结果对998244353取模。


样例输入1

3 2
1 2
2 3

样例输出1

1
499122177

我们用(u, v)表示连接顶点u和v的边。

在第1次操作后,图G将有:

  • 连接顶点1和2的边$(1, 2)$,概率为1/2;
  • 连接顶点2和3的边$(2, 3)$,概率为1/2。

在这两种情况下,图G都是森林,因此当K=1时,答案为1。

在第2次操作后,图G将有:

  • 边$(1, 2)$和$(1, 2)$,概率为1/4;
  • 边$(2, 3)$和$(2, 3)$,概率为1/4;
  • 边$(1, 2)$和$(2, 3)$,概率为1/2。

图G只有当它有边$(1, 2)$和$(2, 3)$时才是森林。因此,所求概率为1/2;当结果对998244353取模时,它为499122177,应该打印出来。


样例输入2

4 5
1 2
1 2
1 4
2 3
2 4

样例输出2

1
758665709
918384805

加入题单

算法标签: