#P7422. 「PMOI-2」城市

    ID: 8207 远端评测题 2500ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP线段树O2优化强连通分量虚树

「PMOI-2」城市

Problem Description

Country PP has NN cities and MM undirected roads. City 11 is the capital, and any two cities can reach each other through roads.

Now Country PP is going to hold ION in the capital. To build the contest venue, each city needs to provide raw materials to the capital. City ii can provide raw material of type cic_i. Each city will have a truck departing from that city and going to the capital along a simple path. If the truck starting from city AA must pass through city BB, then we say that city BB lies on the unavoidable path from city AA to the capital. If for cities A,B,CA, B, C, any simple path from BB to AA and any simple path from CC to AA have no common edges, then we say that cities BB and CC are independent of each other with respect to city AA.

Let f(A,k)f(A,k) be the number of kk-element sets {B1,B2,Bk}\{B_1,B_2,\cdots B_k\} that satisfy all of the following conditions:

  1. For any 1ik1 \le i \le k with ABiA \neq B_i, city AA lies on the unavoidable path from city BiB_i to the capital, and the material supplied by city BiB_i is different from that of city AA.

  2. For any 1i<jk1 \le i < j \le k, BiB_i and BjB_j are independent with respect to AA, and the raw materials supplied by BiB_i and BjB_j are the same.

Define the attractiveness of holding ION as i=1Nk=1Kf(i,k)\sum_{i=1}^N \sum_{k=1}^K f(i,k), where KK is a given constant.

Now, as the leader of Country PP, you want to know the attractiveness of this ION.

Since the answer may be very large, please output the answer modulo 998244353998244353.

Input Format

The first line contains three integers N,M,KN, M, K.

The second line contains NN integers. The ii-th number is the type of raw material cic_i supplied by city ii.

The next MM lines each contain two integers u,vu, v, indicating a road in Country PP. It is guaranteed that there are no multiple edges and no self-loops. (1u,vN,uv1 \le u, v \le N, u \neq v)

Output Format

Output one integer, the answer.

7 7 2
1 2 3 3 1 1 2
1 2
2 3
2 4
3 4
3 5
3 6
4 7
12

Hint

[Sample Explanation]

In the sample, the map of Country PP is as follows:

In the table below, the entry in row ii and column jj represents f(i,j)f(i,j).

44 00
44 00 00
22 11
11 00

So the attractiveness is 4+4+2+1+1=124 + 4 + 2 + 1 + 1 = 12.

[Constraints]

This problem uses bundled testdata.

  • Subtask 1 (10 pts): N,K8N, K \le 8.
  • Subtask 2 (10 pts): K=1K = 1.
  • Subtask 3 (15 pts): K=2K = 2.
  • Subtask 4 (15 pts): the graph is guaranteed to be a tree.
  • Subtask 5 (15 pts): N2000N \le 2000.
  • Subtask 6 (15 pts): N4×104N \le 4 \times 10^4.
  • Subtask 7 (20 pts): no special constraints.

For 100%100\% of the data: 1N5×1051 \le N \le 5 \times 10^5, $1 \le M \le \min\left(10^6, \frac{N \times (N - 1)}{2}\right)$, 1K201 \le K \le 20, 1ci1091 \le c_i \le 10^9.

Warm reminder: The input is large, so please use a fast input method.

Translated by ChatGPT 5