2 1 1 2
1 2
0.5
0.5

## Sample Output

0.500000 0.500000

## Solution

$ans_{x,y}=p_x\times p_y\times ans_{x,y}$（两个人都停在原地）
$~~~~~~~~~~~~~~+(1-p_x)\times(1-p_y)\times\sum ans_{fx,fy}\times\frac{1}{d_{fx}\times d_{fy}}$（两个人都走）
$~~~~~~~~~~~~~~+p_x\times(1-p_y)\times\sum ans_{x,fy}\times\frac{1}{d_{fy}}$（只有第二个人走）
$~~~~~~~~~~~~~~+(1-p_x)\times p_y\times\sum ans_{fx,y}\times\frac{1}{d_{fx}}$（只有第一个人走）

## Code

 1 #include<iostream>
2 #include<cstdio>
3 #include<cmath>
4 #define N (409)
5 using namespace std;
6
7 struct Node{int x,y;}A[N];
8 struct Edge{int to,next;}edge[N];
9 double f[N][N],ans[N],p[N];
10 int n,m,s,e,u,v,c,id_num,id[N][N];
12
14 {
15     Ind[v]++;
16     edge[++num_edge].to=v;
19 }
20
21 void Build()
22 {
23     for (int i=1; i<=c; ++i)
24     {
25         int x=A[i].x,y=A[i].y;
26         if (x!=y) f[i][i]=(1-p[x]*p[y]);
27         else f[i][i]=1;
28         for (int j=head[x]; j; j=edge[j].next)
29             for (int k=head[y]; k; k=edge[k].next)
30             {
31                 int fx=edge[j].to,fy=edge[k].to;
32                 if (fx==fy) continue;
33                 f[i][id[fx][fy]]=-1.0/(Ind[fx]*Ind[fy])*(1-p[fx])*(1-p[fy]);
34             }
35         for (int j=head[x]; j; j=edge[j].next)
36         {
37             int fx=edge[j].to;
38             if (fx==y) continue;
39             f[i][id[fx][y]]=-1.0/(Ind[fx])*(1-p[fx])*p[y];
40         }
41         for (int j=head[y]; j; j=edge[j].next)
42         {
43             int fy=edge[j].to;
44             if (x==fy) continue;
45             f[i][id[x][fy]]=-1.0/(Ind[fy])*p[x]*(1-p[fy]);
46         }
47         if (x==s && y==e) f[i][c+1]=1;
48     }
49 }
50
51 void Gauss()
52 {
53     for (int i=1; i<=c; ++i)
54     {
55         int num=i;
56         for (int j=i+1; j<=c; ++j)
57             if (fabs(f[j][i])>fabs(f[num][i])) num=j;
58         if (num!=i) swap(f[i],f[num]);
59         for (int j=i+1; j<=c; ++j)
60         {
61             double t=f[j][i]/f[i][i];
62             for (int k=i; k<=c+1; ++k)
63                 f[j][k]-=t*f[i][k];
64         }
65     }
66     for (int i=c; i>=1; --i)
67     {
68         for (int j=i+1; j<=c; ++j)
69             f[i][c+1]-=f[i][j]*ans[j];
70         ans[i]=f[i][c+1]/f[i][i];
71     }
72 }
73
74 int main()
75 {
76     scanf("%d%d%d%d",&n,&m,&s,&e);
77     for (int i=1; i<=m; ++i)
78     {
79         scanf("%d%d",&u,&v);
81     }
82     for (int i=1; i<=n; ++i)
83         scanf("%lf",&p[i]);
84     for (int i=1; i<=n; ++i)
85         for (int j=1; j<=n; ++j)
86         {
87             id[i][j]=++c;
88             A[c]=(Node){i,j};
89         }
90     Build();
91     Gauss();
92     for (int i=1; i<=n; ++i)
93         printf("%.6lf ",ans[id[i][i]]);
94 }