Codeforces Round 1046 (Div. 1)
C
By the Assignment
Codeforces
2000
原题
← BD1 →
翻译中…

For an undirected connected graph of $n$ vertices, where the $i$-th vertex has a weight of $v_i$, we define the value of a simple path$^{\text{∗}}$ $l_1, l_2, \ldots, l_m$ as $v_{l_1}\oplus v_{l_2}\oplus\cdots\oplus v_{l_m}$$^{\text{†}}$. We call the graph balanced if and only if:

翻译中…
  • For every $1\le p \lt q\le n$, all simple paths from $p$ to $q$ have the same value.
翻译中…

Aquawave has given you an undirected connected graph of $n$ vertices and $m$ edges, and the $i$-th vertex in the graph has a weight of $a_i$. However, some of the weights are missing, represented by $-1$.

翻译中…

Aquawave wants to assign an integer weight between $0$ and $V-1$ to each vertex with $a_i=-1$, so that the graph will be balanced.

翻译中…

You have to help Aquawave find the number of ways to assign weights to achieve the goal, modulo $998\,244\,353$.

翻译中…

$^{\text{∗}}$A simple path from $c$ to $d$ is a sequence of vertices $l_1, l_2, \ldots, l_m$, where $l_1=c$, $l_m=d$, such that there is an edge between $l_i$ and $l_{i+1}$ for every $1\le i\le m-1$, and there are no repeated vertices, i.e. $l_i\ne l_j$ for $1\le i \lt j\le n$. $^{\text{†}}$$\oplus$ denotes the bitwise XOR operation.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains three integers $n$, $m$, and $V$ ($2\le n\le 2\cdot 10^5$, $n-1\le m\le \min\left(\frac{n(n-1)}{2}, 4\cdot 10^5\right)$, $1\le V\le 10^9$) — the number of vertices, the number of edges, and the upper bound of weights.

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1\le a_i\le V-1$) — the weights of the vertices. $a_i=-1$ represents that the weight of the $i$-th vertex is missing.

翻译中…

Then $m$ lines follow, the $i$-th line containing two integers $u$ and $v$ ($1\le u,v\le n$) — the two vertices that the $i$-th edge connects.

翻译中…

It is guaranteed that the given graph is simple and connected.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$, and the sum of $m$ over all test cases does not exceed $4\cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the number of ways to assign weights to make the graph balanced, modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first test case, there are four possible assignments:

翻译中…
  • $a=[0,0,0,0]$;
  • $a=[0,0,0,1]$;
  • $a=[0,0,0,2]$;
  • $a=[0,0,0,3]$.
翻译中…

It can be shown that all of these assignments can make the graph balanced.

翻译中…

In the second test case, we will pick $(p,q)=(1,5)$. The simple path $1\to 2\to 5$ has a value of $2\oplus 2\oplus 2=2$, and the simple path $1\to 3\to 5$ has a value of $2\oplus a_3\oplus 2=a_3$, so the only possible value for $a_3$ is $2$. It can be shown that $a_3=2$ can make the graph balanced.

翻译中…

In the fifth test case, the given graph is a tree, so there is only one simple path between any two vertices. Thus, we can assign an arbitrary value between $0$ and $V-1$ to each $a_i$, and the answer is $1\,000\,000\,000^3\bmod998\,244\,353=747\,068\,572$.

翻译中…

样例

Input #1
5
4 4 4
-1 -1 -1 -1
1 2
2 3
1 3
4 3
5 6 7
2 2 -1 2 2
1 2
1 3
1 4
2 5
3 5
4 5
7 8 9
-1 -1 -1 -1 0 -1 0
1 2
2 3
3 4
1 4
1 5
5 6
7 6
7 5
5 8 1000000000
1 2 3 4 -1
1 2
3 2
3 5
5 1
2 4
4 3
2 5
1 4
5 4 1000000000
-1 2 -1 3 -1
1 2
1 3
2 4
2 5
Output #1
4
1
9
0
747068572
InputCopy OutputCopy
题目信息
题号
2135C
时间限制
4 s
内存限制
512 MB
标签
二分
位运算
组合数学
DFS 及类似
并查集
图论
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。