A9497. DZY Loves Games
编程题
普及/提高-
知识点
题目描述
Today DZY begins to play an old game. In this game, he is in a big maze with $n$ rooms connected by $m$ corridors (each corridor allows to move in both directions). You can assume that all the rooms are connected with corridors directly or indirectly.
DZY has got lost in the maze. Currently he is in the first room and has $k$ lives. He will act like the follows:
- Firstly he will randomly pick one of the corridors going from his current room. Each outgoing corridor has the same probability to be picked.
- Then he will go through the corridor and then the process repeats.
There are some rooms which have traps in them. The first room definitely has no trap, the $n$ -th room definitely has a trap. Each time DZY enters one of these rooms, he will lost one life. Now, DZY knows that if he enters the $n$ -th room with exactly 2 lives, firstly he will lost one live, but then he will open a bonus round. He wants to know the probability for him to open the bonus round. Please, help him.
DZY has got lost in the maze. Currently he is in the first room and has $k$ lives. He will act like the follows:
- Firstly he will randomly pick one of the corridors going from his current room. Each outgoing corridor has the same probability to be picked.
- Then he will go through the corridor and then the process repeats.
There are some rooms which have traps in them. The first room definitely has no trap, the $n$ -th room definitely has a trap. Each time DZY enters one of these rooms, he will lost one life. Now, DZY knows that if he enters the $n$ -th room with exactly 2 lives, firstly he will lost one live, but then he will open a bonus round. He wants to know the probability for him to open the bonus round. Please, help him.
输入格式
The first line contains three integers $n,m,k (2<=n<=500; 1<=m<=10^{5}; 2<=k<=10^{9})$ .
The second line contains $n$ integers, each of them is either $0$ or $1$ . If the $i$ -th number is $1$ , then the $i$ -th room has a trap, otherwise it has not a trap. Please note, that the number of rooms with a trap is no more than $101$ . It is guaranteed that the first room has no trap, and the $n$ -th room has a trap.
Then $m$ lines follows. Each of them contains two integers $u_{i},v_{i} (1<=u_{i},v_{i}<=n; u_{i}≠v_{i})$ , meaning that current corridor connects two rooms $u_{i}$ and $v_{i}$ . It is guaranteed that the corridor system is connected.
The second line contains $n$ integers, each of them is either $0$ or $1$ . If the $i$ -th number is $1$ , then the $i$ -th room has a trap, otherwise it has not a trap. Please note, that the number of rooms with a trap is no more than $101$ . It is guaranteed that the first room has no trap, and the $n$ -th room has a trap.
Then $m$ lines follows. Each of them contains two integers $u_{i},v_{i} (1<=u_{i},v_{i}<=n; u_{i}≠v_{i})$ , meaning that current corridor connects two rooms $u_{i}$ and $v_{i}$ . It is guaranteed that the corridor system is connected.
输出格式
Print the only real number — the probability for DZY to open the bonus round. The answer will be considered correct if its relative or absolute error doesn't exceed $10^{-4}$ .
输入输出样例
输入 #1
5 5 3 0 0 1 0 1 1 2 2 3 3 4 4 5 1 2
输出 #1
0.25000000
输入 #2
3 2 2 0 1 1 1 2 2 3
输出 #2
-0.00000000
输入 #3
2 1 3 0 1 1 2
输出 #3
1.00000000