1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| #include "iostream" #include "algorithm" #include "cstring" #include "cstdio" #include "cmath" #include "vector" #include "map" #include "set" #include "queue" using namespace std; #define MAXN 406
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedef long long ll; #define eps 1e-7 int n , m , a , b; int G[MAXN][MAXN] , deg[MAXN] , id[MAXN][MAXN] , tot = 0; double p[MAXN]; int sgn( double a ) { return fabs( a ) < eps ? 0 : a > 0 ? 1 : -1; } double A[MAXN][MAXN]; void solve() { cin >> n >> m >> a >> b; int u , v; rep( i , 1 , m ) scanf("%d%d",&u,&v) , G[u][v] = G[v][u] = 1 , ++ deg[v] , ++ deg[u]; rep( i , 1 , n ) scanf("%lf",p + i); rep( i , 1 , n ) rep( j , 1 , n ) id[i][j] = ++ tot; int dx; rep( i , 1 , n ) { rep( j , 1 , n ) { dx = id[i][j]; rep( v , 1 , n ) if( G[i][v] && j != v ) { A[dx][id[v][j]] += p[j] * ( p[v] - 1 ) / deg[v]; } rep( u , 1 , n ) if( G[j][u] && i != u ) { A[dx][id[i][u]] += p[i] * ( p[u] - 1 ) / deg[u]; } rep( v , 1 , n ) if( G[i][v] ) rep( u , 1 , n ) if( G[u][j] && u != v ) { A[dx][id[v][u]] -= ( 1 - p[v] ) * ( 1 - p[u] ) / deg[v] / deg[u]; } A[dx][dx] = 1 - ( ( i != j ) ? p[i] * p[j] : 0 ); } } A[id[a][b]][tot + 1] = 1;
for( int i = 1 ; i <= tot ; ++ i ) { int mxpos = i; for( int j = i + 1 ; j <= tot ; ++ j ) if( fabs( A[j][i] ) - fabs( A[mxpos][i] ) > eps ) mxpos = j; swap( A[i] , A[mxpos] ); double c = A[i][i]; A[i][i] = 1; rep( j , i + 1 , tot + 1 ) A[i][j] /= c; for( int j = 1 ; j <= tot ; ++ j ) if( j != i ) { double cc = A[j][i]; A[j][i] = 0; for( int k = i + 1 ; k <= tot + 1 ; ++ k ) A[j][k] -= cc * A[i][k]; } } for( int i = 1 ; i <= n ; ++ i ) printf("%lf ",A[id[i][i]][tot + 1]); }
signed main() {
solve(); }
|