Professional Documents
Culture Documents
2nd Question
2nd Question
0 2 2
As we can see, this process continues until all the houses are
infected. The order in whicth the uninfected houses are infected is
called an infection sequence. Find the total number of distinct
infection sequences. Since the answer could be large print it with
modulo 1000000007.
Input Format
The first line contains an
integer, n, denoting the total number of
houses
The next line contains an integer, m, denoting the number of
elements in infect.
Each line i of the msubsequent lines (where 0si<m) contains
an integer
describing infect[i]
Constraints w
ww
wwww
1 n<= 10 5 w
ww
1< infect|il<= n
There are 4
A
1 houses. Initially
the only infected
house is 1. On the
1st day, house 2
gets infected by
th@gmal.o ww
www
wwwwwww
AW
www
ww
ww ww
wWwww
www.wwww
house 1. On the
2nd day, house 3
gets infected by
TRW house 2. On the
w 3rd day, house 4
gets infected by
house 3. The onlyy
possible infection
sequence is
[2.3.4
5 4 Initially, only housse
3 is infected. On
3 Day 1, houses 2
and 4 get infected.
deananth@gmail.com
AMWW.Awww.ww.wAWAWAAWMAMAMAWI
WA
MAAww.
WAWAM [2.4,1.5]. 14.2.1,5].
w
12.4.5.11. 14.2.5.11
Www
w
ww ww
6 Www WwY Initially, houses 3
6 www
[2.4,6.1). [2.6.4,1]
[4.6.2.11. [4,2.6.1].
[6,2,4.1], [6,4.2.1]