Components

AtCoder
IDabc287_f
Time2000ms
Memory256MB
Difficulty
You are given a tree with $N$ vertices. The vertices are numbered $1$ through $N$, and the $i$\-th edge connects vertex $a_i$ and vertex $b_i$. Solve the following problem for each $x=1,2,\ldots,N$: * There are $(2^N-1)$ non-empty subsets $V$ of the tree's vertices. Find the number, modulo $998244353$, of such $V$ that the subgraph induced by $V$ has exactly $x$ connected components. What is an induced subgraph? Let $S$ be the subset of the vertices of a graph $G$; then the subgraph of $G$ induced by $S$ is a graph whose vertex set is $S$ and whose edge set consists of all edges of $G$ whose both ends are contained in $S$. ## Constraints * $1 \leq N \leq 5000$ * $1 \leq a_i \lt b_i \leq N$ * The given graph is a tree. ## Input The input is given from Standard Input in the following format: $N$ $a_1$ $b_1$ $\vdots$ $a_{N-1}$ $b_{N-1}$ [samples]
Samples
Input #1
4
1 2
2 3
3 4
Output #1
10
5
0
0

The induced subgraph will have two connected components in the following five cases and one in the others.

*   $V = {1,2,4}$
*   $V = {1,3}$
*   $V = {1,3,4}$
*   $V = {1,4}$
*   $V = {2,4}$
Input #2
2
1 2
Output #2
3
0
Input #3
10
3 4
3 6
6 9
1 3
2 4
5 6
6 10
1 8
5 7
Output #3
140
281
352
195
52
3
0
0
0
0
API Response (JSON)
{
  "problem": {
    "name": "Components",
    "description": {
      "content": "You are given a tree with $N$ vertices. The vertices are numbered $1$ through $N$, and the $i$\\-th edge connects vertex $a_i$ and vertex $b_i$. Solve the following problem for each $x=1,2,\\ldots,N$: ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc287_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a tree with $N$ vertices. The vertices are numbered $1$ through $N$, and the $i$\\-th edge connects vertex $a_i$ and vertex $b_i$.\nSolve the following problem for each $x=1,2,\\ldots,N$:\n\n...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments