loj#P3235. 「POI2019 R1」Przedszkole
「POI2019 R1」Przedszkole
Description
Source Problem: POI XXVII - I etap 「Przedszkole」
Each morning the kindergarten teacher hands out toys to the children. To keep everything in order, each of the children receives exactly one toy. Each child may either play on their own or in pair together with another child, but only if the two like each other.
The teacher has kinds of toys. She is wondering how many different ways there are to distribute the toys among the children in such a way that every two children who like each other receive different kinds (so that they have two kinds to play with should they form a pair).
Input Format
In the first input line, there is a triplet of integers , , , separated by single spaces, which respectively specify: the number of children in the kindergarten, the number of pairs of children who like each other, and the number of queries.
The lines that follow specify the pairs of children who like each other: each such line contains two positive integers ai and bi which are the numbers of the two children who like each other. For simplicity, we number children from to . No pair appears more than once on input.
Finally, the last lines contain the queries: the -th of these contains an integer .
Output Format
Exactly lines should be printed to output: the -th of these should contain the number of ways the toys can be distributed among the children if there are kinds. The numbers should be reported modulo (i.e., the remainder of division of the actual number by should be printed).
4 4 1
1 2
2 3
1 3
3 4
3
12
Additional Samples
See prz/prz*.in
and prz/prz*.out
for additional samples.
- Additional Sample 1: (all children like each other), two queries for ;
- Additional Sample 2: , query for ;
- Additional Sample 3: , five queries for random ;
- Additional Sample 4: , the pairs of children who like each other are No. and No. for as well as No. and No. ; three queries for .
Constraints
The set of tests consists of the following subsets. Within each subset, there may be several tests. Within each subset, at least of the score is awarded for tests in which .
For all data, it is guaranteed that $1 \le n \le 10^5, 0 \le m \le \min(10^5, n(n-1)/2), 1 \le z \le 1000, 1 \le a_i, b_i \le n, 1 \le k_i \le 10^9$.
Subtask # | Additional Constraints | Score |
---|---|---|
Each child likes exactly two other children |