#P6238. [JSOI2011] 序的计数

[JSOI2011] 序的计数

Description

Given an undirected graph G={V,E}G=\{V,E\}, where n=Vn=|V| and m=Em=|E|. The nn vertices are numbered from 11 to nn.

Now we run DFS, i.e., depth-first search. It is easy to see that while performing DFS traversal, we can record the visited vertices in the order they are first visited. In this way we obtain a sequence of vertices, which is a permutation of 11 to nn. We call this permutation a possible DFS order.

Obviously, not every permutation of 11 to nn can be a DFS order. Now suppose the DFS process is halfway done, and it has visited exactly kk distinct vertices {u1,u2,...,uk}\{u_1,u_2,...,u_k\}. Then clearly, the DFS order corresponding to this halfway DFS process should be a permutation of these kk numbers.

Now, please compute how many different DFS orders of length kk can correspond to the currently visited kk vertices.

Input Format

The first line contains three integers separated by spaces: nn, mm, and kk.

The next mm lines each contain two positive integers uu and vv separated by one space, indicating that graph GG has an edge (u,v)(u,v).

The last line contains kk positive integers separated by spaces, describing the kk vertices that have already been visited. The ii-th number is uiu_i. The testdata guarantees that these kk numbers are given in increasing order.

Output Format

Output one line with one number, which is the number of possible DFS orders.

8 7 5
1 2
1 3
1 6
3 4
2 5
7 8
8 7
1 2 3 7 8 
4

Hint

Constraints

  • For 100%100\% of the testdata, 1n1001 \le n \le 100, 1m5×1031 \le m \le 5 \times 10^3, 1k181 \le k \le 18, 1uin1 \le u_i \le n, 1u,vn1 \leq u, v \leq n.

Translated by ChatGPT 5