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 vertices and edges. The -th edge connects and and has weight . Multiple edges and self-loops are not guaranteed to be absent.
xtq thinks that if there exists a path starting from and ending at such that the XOR sum of the weights of all edges that are traversed an odd number of times by this path equals , then the ordered pair is “clever” with respect to .
Now, xtq asks you queries. For each query, ask how many distinct ordered pairs are clever with respect to . Note that may equal , and if , then and are considered different.
Input Format
The first line contains three positive integers .
The next lines each contain three integers .
The next lines each contain one integer , representing a query.
Output Format
Output lines. Each line answers one query, and you should print the result modulo .
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 :
, and are similar; , and is similar.
Ordered pairs that are clever with respect to :
, and is similar; , and is similar.
Ordered pairs that are clever with respect to : similar to .
Constraints
| Test Point ID | Special Restriction | |||
|---|---|---|---|---|
| None | ||||
| ^ | ||||
| A tree | ||||
| ^ | ^ | None | ||
| A tree | ||||
| ^ | ^ | None | ||
| ^ | ||||
| ^ | ^ | |||
| A tree | ||||
| ^ | ^ | ^ | ||
| None | ||||
| ^ | ^ | |||
| ^ | ||||
For 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