#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
using namespace std;
#define N 23
vector<int> g[N];
int n, m, a, b;
int d[N];
double p[N];
double A[N * N][N * N], X[N * N][N], B[N * N][N];
int mp[N][N];
int tot;
int f(int a, int b) {
if(a > b) swap(a, b);
return mp[a][b];
}
void get_A() {
for(int i = 1; i <= n; ++i) {
for(int j = i; j <= n; ++j) {
mp[i][j] = ++tot;
}
}
for(int i = 1; i <= n; ++i) {
A[mp[i][i]][mp[i][i]] = 1;
for(int j = i + 1; j <= n; ++j) {
int t = f(i, j);
A[t][t] += 1 - p[i] * p[j];
for(int x = 0; x < g[i].size(); ++x) {
int u = g[i][x];
int w = f(j, u);
A[t][w] += - (1 - p[i]) / d[i] * p[j];
}
for(int y = 0; y < g[j].size(); ++y) {
int v = g[j][y];
int w = f(i, v);
A[t][w] += - p[i] * (1 - p[j]) / d[j];
}
for(int x = 0; x < g[i].size(); ++x) {
for(int y = 0; y < g[j].size(); ++y) {
int u = g[i][x];
int v = g[j][y];
int w = f(u, v);
A[t][w] += -(1 - p[i]) / d[i] * (1 - p[j]) / d[j];
}
}
}
}
}
void get_B() {
for(int i = 1; i <= n; ++i) {
B[f(i, i)][i] = 1;
}
}
void gauss() {
for(int i = 1; i <= tot; ++i) {
int u = i;
double tmp = fabs(A[i][i]);
for(int j = i; j <= tot; ++j) {
if(fabs(A[j][i]) > tmp) {
tmp = fabs(A[j][i]);
u = j;
}
}
for(int j = i; j <= tot; ++j) swap(A[i][j], A[u][j]);
for(int j = 1; j <= n; ++j) swap(B[i][j], B[u][j]);
for(int j = i + 1; j <= tot; ++j) {
if(fabs(A[j][i]) > 1e-14) {
double t = A[j][i] / A[i][i];
for(int k = i; k <= tot; ++k) A[j][k] -= A[i][k] * t;
for(int k = 1; k <= n; ++k) B[j][k] -= B[i][k] * t;
}
}
}
for(int i = 1; i <= n; ++i) {
for(int j = tot; j >= 1; --j) {
X[j][i] = B[j][i];
for(int k = j + 1; k <= tot; ++k) {
X[j][i] -= X[k][i] * A[j][k];
}
X[j][i] /= A[j][j];
}
}
}
int main() {
scanf("%d%d%d%d", &n, &m, &a, &b); if(a > b) swap(a, b);
for(int i = 1; i <= m; ++i) {
int u, v;
scanf("%d%d", &u, &v);
g[u].push_back(v);
g[v].push_back(u);
d[u]++;
d[v]++;
}
for(int i = 1; i <= n; ++i) scanf("%lf", &p[i]);
get_A();
get_B();
gauss();
for(int i = 1; i <= n; ++i) {
printf("%.12lf%c", X[f(a, b)][i], i == n? '\n': ' ');
}
return 0;
}
CodeForces 113D Museum (高斯消元)
最新推荐文章于 2020-06-22 22:49:06 发布