1994. Strange Couple

单点时限: 2.0 sec

内存限制: 256 MB

Alice and Bob are going to drive from their home to a theater for a date. They are very challenging – they have no maps with them even though they don’t know the route at all (since they have just moved to their new home). Yes, they will be going just by their feeling.

The town they drive can be considered as an undirected graph with a number of intersections (vertices) and roads (edges). Each intersection may or may not have a sign. On intersections with signs, Alice and Bob will enter the road for the shortest route. When there is more than one such roads, they will go into one of them at random.

On intersections without signs, they will just make a random choice. Each random selection is made with equal probabilities. They can even choose to go back to the road they have just come along, on a random selection.

Calculate the expected distance Alice and Bob will drive before reaching the theater.

输入格式

The input has the following format:

$n \ s \ t \ \
q_{1} \ q_{2} \ \ldots \ q_{n} \ \
a_{11} \ a_{12} \ \ldots \ a_{1n} \ \
a_{21} \ a_{22} \ \ldots \ a_{2n} \ \
\vdots \ \
a_{n1} \ a_{n2} \ \ldots \ a_{nn}$

$n$ is the number of intersections ($n \le 100$). $s$ and $t$ are the intersections the home and the theater are located respectively ($1 \le s, t \le n, s \ne t$); $q_i$ (for $1 \le i \le n$) is either $1$ or $0$, where $1$ denotes there is a sign at the $i$-th intersection and $0$ denotes there is not; $a_{ij}$ (for $1 \le i, j \le n$) is a positive integer denoting the distance of the road connecting the $i$-th and $j$-th intersections, or $0$ indicating there is no road directly connecting the intersections. The distance of each road does not exceed $10$.

Since the graph is undirectional, it holds $a_{ij}=a_{ji}$ for any $1 \le i, j \le n$. There can be roads connecting the same intersection, that is, it does not always hold $a_{ii} = 0$. Also, note that the graph is not always planar.

输出格式

Print the expected distance accurate to $10^{-8}$, or impossible (without quotes) if there is no route to get to the theater. The distance may be printed with any number of digits after the decimal point.

样例

Input
5 1 5
1 0 1 0 0
0 2 1 0 0
2 0 0 1 0
1 0 0 1 0
0 1 1 0 1
0 0 0 1 0
Output
8.50000000

3 人解决,6 人已尝试。

3 份提交通过,共有 55 份提交。

8.8 EMB 奖励。

创建: 14 年,6 月前.

修改: 6 年,10 月前.

最后提交: 3 年,12 月前.

来源: Japan

题目标签