Tree Vertices XOR

AtCoder
IDagc052_f
Time4000ms
Memory256MB
Difficulty
You are given a tree with $N$ vertices. The vertices are numbered from $1$ to $N$, and the $i$\-th edge connects vertices $u_i$ and $v_i$. Initially, on each vertex of the tree is written number $1$. In one operation, you can do the following: * Choose any vertex $v$ of the tree. Let $X$ be the **XOR** of the values written in the neighbors of $v$. Then, if the number written on $v$ is $a_v$, replace it by $(a_v\ \mathrm{XOR}\ X)$. You can perform this operation any finite (maybe zero) number of times. How many configurations can you achieve? As this number can be large, output it modulo $998244353$. Two configurations are called different if there exists a vertex $v$, such that the numbers written in $v$ in these configurations are different. ## Constraints * $3 \le N \le 2\cdot 10^5$ * $1\le u_i, v_i \le N$ * $u_i \neq v_i$ * The input represents a valid tree. ## Input Input is given from Standard Input in the following format: $N$ $u_1$ $v_1$ $u_2$ $v_2$ $\vdots$ $u_{N-1}$ $v_{N-1}$ [samples]
Samples
Input #1
4
1 2
2 3
3 4
Output #1
10

We can get the following configurations ($abcd$ means vertices $1,2,3,4$ have $a,b,c,d$ written on them): $1111$, $1110$, $1100$, $1000$, $0111$, $0110$, $0100$, $0011$, $0010$, $0001$.
Input #2
5
1 2
1 3
1 4
1 5
Output #2
24
Input #3
6
1 3
2 3
3 4
4 5
4 6
Output #3
40
Input #4
9
1 2
2 3
1 4
4 5
1 6
6 7
7 8
8 9
Output #4
255
API Response (JSON)
{
  "problem": {
    "name": "Tree Vertices XOR",
    "description": {
      "content": "You are given a tree with $N$ vertices. The vertices are numbered from $1$ to $N$, and the $i$\\-th edge connects vertices $u_i$ and $v_i$. Initially, on each vertex of the tree is written number $1$. ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 4000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "agc052_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a tree with $N$ vertices. The vertices are numbered from $1$ to $N$, and the $i$\\-th edge connects vertices $u_i$ and $v_i$.\nInitially, on each vertex of the tree is written number $1$.\n...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments