luogu#P5107. 能量采集

能量采集

Problem Description

The statement has been modified. Please pay attention.

Please compute the following expression: i=1Nj=1Ngcd(i,j)\sum_{i=1}^N\sum_{j=1}^Ngcd(i,j), and take the answer modulo a large prime number.

Sorry, I read the wrong script.

You are given a directed graph with nn nodes and mm edges. Each node has an initial energy value aia_i.

Every second, the energy at each node flows equally to all of its outgoing edges. In addition, one share flows to itself (you may treat this as having a self-loop).

Now dkwdkw has qq queries. Each query gives a time tt, and dkwdkw wants to know the energy at each node after tt seconds.

The graph is not guaranteed to be free of multiple edges or self-loops. All answers are taken modulo 998244353998244353.

Input Format

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

The second line contains nn integers, from a1a_1 to ana_n, representing the initial energy.

The next mm lines each contain two positive integers xi,yix_i,y_i, representing a directed edge from xix_i to yiy_i. We assume the nodes are numbered from 11 to nn.

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

Output Format

To avoid overly large output, for each query you only need to output one line with one non-negative integer, which is the XOR sum of the energies (modulo) of the nn nodes, and then taken modulo 998244353998244353.

5 10 3
4 5 3 2 7 
4 1
1 4
2 1
3 2
1 2
5 1
2 4
2 1
2 4
1 4
1
2
3

15
548614965
80769513

Hint

For 30%30\% of the testdata, 1t501\le t \le 50.

For 60%60\% of the testdata, 1q501\le q\le 50.

For 80%80\% of the testdata, 1q10001\le q\le 1000.

For 100%100\% of the testdata, $1\le n\le 50,1\le m\le n\times (n-1),1\le q\le 5\times 10^4,0< a_i< 998244353,1\le t\le 10^9$.

Translated by ChatGPT 5