​http://www.elijahqi.win/archives/3305​​​
Description

Input

Output

Sample Input

2 1 1 2
1 2
0.5
0.5
Sample Output

0.500000 0.500000
HINT

dp[i][j]=dp[i][j]∗p[i]∗p[j]+∑(i,x)∈E,(j,y)∈Edp[x][j]∗(1−p[i])∗p[j]/d[i]+dp[i][y]∗(1−p[j])∗p[i]/d[j]+dp[x][y]∗(1−p[i])∗(1−p[j])/d[i]/d[j] d p [ i ] [ j ] = d p [ i ] [ j ] ∗ p [ i ] ∗ p [ j ] + ∑ ( i , x ) ∈ E , ( j , y ) ∈ E d p [ x ] [ j ] ∗ ( 1 − p [ i ] ) ∗ p [ j ] / d [ i ] + d p [ i ] [ y ] ∗ ( 1 − p [ j ] ) ∗ p [ i ] / d [ j ] + d p [ x ] [ y ] ∗ ( 1 − p [ i ] ) ∗ ( 1 − p [ j ] ) / d [ i ] / d [ j ]

#include<cmath>
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
return x*f;
}
const int N=440;
struct node{
int y,next;
}data[N<<1];
double a[N][N],p[22],ans[N];int d[22],h[N],id[22][22],cnt,A,B,n,m,num;
inline void gauss(){
for (int i=1;i<=cnt;++i){
int owo=i;
for (int j=i+1;j<=cnt;++j) if (fabs(a[j][i])>fabs(a[owo][i])) owo=j;
swap(a[owo],a[i]);double tmp;
for (int j=i+1;j<=cnt;++j){
tmp=a[j][i]/a[i][i];
for (int k=i;k<=cnt+1;++k) a[j][k]-=tmp*a[i][k];
}
}
for (int i=cnt;i;--i){
for (int j=i+1;j<=cnt;++j) a[i][cnt+1]-=ans[j]*a[i][j];
ans[i]=a[i][cnt+1]/a[i][i];
}
}
int main(){
freopen("bzoj3270.in","r",stdin);
for (int i=1;i<=m;++i){
data[++num].y=y;data[num].next=h[x];h[x]=num;
data[++num].y=x;data[num].next=h[y];h[y]=num;
}
for (int i=1;i<=n;++i) scanf("%lf",&p[i]);
for (int i=1;i<=n;++i)
for (int j=1;j<=n;++j) {id[i][j]=++cnt;if (i!=j) a[id[i][j]][id[i][j]]=p[i]*p[j]-1;else
a[id[i][j]][id[i][j]]-=1;}
for (int i=1;i<=n;++i){
for (int j=1;j<=n;++j){
if (i==j) continue;
for (int owo=h[i];owo;owo=data[owo].next){
int x=data[owo].y,y=j;
a[id[x][y]][id[i][j]]+=(1-p[i])/d[i]*p[j];
}
for (int owo=h[j];owo;owo=data[owo].next){
int y=data[owo].y,x=i;
a[id[x][y]][id[i][j]]+=p[i]*(1-p[j])/d[j];
}
for (int k=h[i];k;k=data[k].next){
for (int z=h[j];z;z=data[z].next){
int x=data[k].y,y=data[z].y;
a[id[x][y]][id[i][j]]+=(1-p[i])*(1-p[j])/d[j]/d[i];
}
}
}
}a[id[A][B]][cnt+1]=-1;gauss();
for (int i=1;i<=n;++i) printf("%f\n",ans[id[i][i]]);
return 0;
}