Paths

Count simple paths in a vertex-colored graph where every vertex on the path has a distinct color, counting both directions separately.

Hard8GraphDFSBacktrackingDynamic programmingNo attempts yetTime limit3sMemory limit1024 MB

Problem

A graph consists of a set of vertices and a set of edges, each joining two vertices.

A path in the graph is an ordered list of vertices v1,v2,,vtv_1, v_2, \dots, v_t with t2t \ge 2 such that consecutive vertices are joined by an edge. Only simple paths are considered here, so no vertex appears more than once. The order matters: lists containing the same vertices in a different order count as different paths.

Each vertex has one of KK colors. Count the simple paths in which no two vertices share a color, so no color appears twice within one path.

Input

The first line contains three integers NN (number of vertices), MM (number of edges), and KK (number of colors), separated by spaces.

The second line contains NN integers c1,c2,,cNc_1, c_2, \dots, c_N (1ciK1 \le c_i \le K), where cic_i is the color of vertex ii.

Each of the next MM lines contains two integers a,ba, b (1a,bN1 \le a, b \le N, aba \ne b), the endpoints of one edge. There is at most one edge between any pair of vertices. The graph may be disconnected.

Output

Print the number of simple paths whose vertices all have distinct colors. Every counted path contains at least two vertices, and two paths that traverse the same vertices in opposite directions are counted separately. The answer is always smaller than 101810^{18}.

Hint

Because all colors in a counted path must differ, a path contains at most KK vertices. A list with a single vertex is not a path, and any list repeating a color is excluded. The answer fits in a 64-bit signed integer, so print it directly with no modulo.