Ex - We Love Forest

AtCoder
IDabc253_h
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
Input #1
3 2
1 2
2 3
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.
Input #2
4 5
1 2
1 2
1 4
2 3
2 4
Output #2
1
758665709
918384805
API Response (JSON)
{
  "problem": {
    "name": "Ex - We Love Forest",
    "description": {
      "content": "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 oper",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc253_h"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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$.\nYou will perform the following oper...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments