luogu#P5169. xtq 的异或和

xtq 的异或和

Background

xtq started studying discrete mathematics a lot when he was in sixth grade. One day, he was thinking while looking at a very dense graph.

Problem Description

xtq has an undirected connected graph with nn vertices and mm edges. The ii-th edge connects sis_i and tit_i and has weight wiw_i. Multiple edges and self-loops are not guaranteed to be absent.

xtq thinks that if there exists a path starting from uu and ending at vv such that the XOR sum of the weights of all edges that are traversed an odd number of times by this path equals xx, then the ordered pair (u,v)(u,v) is “clever” with respect to xx.

Now, xtq asks you qq queries. For each query, ask how many distinct ordered pairs (u,v)(u,v) are clever with respect to xx. Note that uu may equal vv, and if uvu \neq v, then (u,v)(u,v) and (v,u)(v,u) are considered different.

Input Format

The first line contains three positive integers n,m,qn,m,q.

The next mm lines each contain three integers si,ti,wis_i,t_i,w_i.

The next qq lines each contain one integer xx, representing a query.

Output Format

Output qq lines. Each line answers one query, and you should print the result modulo 998244353998244353.

3 3 3
1 2 0
2 3 1
3 1 2
0
1
2
5
4
4
4 3 2
1 2 1
2 3 6
2 4 7
6
7
4
4

Hint

Sample Explanation 1

Ordered pairs that are clever with respect to 00:

(1,1):121(1,1): 1 \Rightarrow 2 \Rightarrow 1, and (2,2),(3,3)(2,2),(3,3) are similar; (1,2):12(1,2): 1 \Rightarrow 2, and (2,1)(2,1) is similar.

Ordered pairs that are clever with respect to 11:

(2,3):23(2,3):2 \Rightarrow 3, and (3,2)(3,2) is similar; (1,3):123(1,3):1 \Rightarrow 2 \Rightarrow 3, and (3,1)(3,1) is similar.

Ordered pairs that are clever with respect to 22: similar to 11.

Constraints

Test Point ID nn mm wi,x,q1\, w_i,x,q-1 Special Restriction
11 5\le 5 10\le 10 <4< 4 None
22 10\le 10 50\le 50 <8< 8 ^
33 100\le 100 =n1= n-1 <128< 128 A tree
44 ^ 500\le 500 ^ None
55 1000\le 1000 =n1= n-1 <1024< 1024 A tree
66 ^ 5000\le 5000 ^ None
77 1×105\le 1 \times 10^5 3×105\le 3\times 10^5 ^
88 ^ ^
99 =n1= n-1 <262144< 262144 A tree
1010 ^ ^ ^
1111
1212
1313 n+11\le n+11 None
1414 ^ ^
1515 3×105\le 3\times 10^5
1616 ^
1717
1818
1919
2020

For 100%100\% of the testdata, $1\le n\le 10^5,n-1\le m\le 3*10^5,0\le w_i,x< 262144,0\le q\le 262144$.

Translated by ChatGPT 5