#P6238. [JSOI2011] 序的计数
[JSOI2011] 序的计数
Description
Given an undirected graph , where and . The vertices are numbered from to .
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 to . We call this permutation a possible DFS order.
Obviously, not every permutation of to can be a DFS order. Now suppose the DFS process is halfway done, and it has visited exactly distinct vertices . Then clearly, the DFS order corresponding to this halfway DFS process should be a permutation of these numbers.
Now, please compute how many different DFS orders of length can correspond to the currently visited vertices.
Input Format
The first line contains three integers separated by spaces: , , and .
The next lines each contain two positive integers and separated by one space, indicating that graph has an edge .
The last line contains positive integers separated by spaces, describing the vertices that have already been visited. The -th number is . The testdata guarantees that these 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 of the testdata, , , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号