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
|
#include <bits/stdc++.h> #define Go(i , x , y) for(register int i = x; i <= y; i++) #define God(i , y , x) for(register int i = y; i >= x; i--)
const int N = 300 + 10; int n , m , p , q , u , v , deg[N]; double g[N][N]; bool w[N][N];
void Gauss() { Go(i , 1 , n) { int now = i; Go(j , i+1 , n) if(fabs(g[now][i]) < fabs(g[j][i])) now = j; Go(j , 1 , n+1) std::swap(g[i][j] , g[now][j]);
Go(j , i+1 , n+1) g[i][j] /= g[i][i]; g[i][i] = 1; Go(j , i+1 , n) { Go(k , i+1 , n+1) { g[j][k] -= g[j][i] * g[i][k]; } g[j][i] = 0; } } God(i , n , 1) { Go(j , i+1 , n) g[i][n+1] -= g[i][j] * g[j][n+1]; g[i][n+1] /= g[i][i]; g[i][i] = 1; } } int main() { scanf("%d%d%d%d", &n, &m, &p, &q); double weight = (1.0 * p) / (1.0 * q); Go(i, 1, m) { scanf("%d%d", &u, &v); w[u][v] = 1; w[v][u] = 1; ++deg[u]; ++deg[v]; }
Go(i, 1, n) { g[i][i] = -1; Go(j, 1, n) if(w[i][j] == 1) g[i][j] += (1.0 - weight) * (1.0 / (double)(deg[j])); }
g[1][n + 1] = -1; Gauss(); Go(i , 1 , n) std::cout << std::fixed << std::setprecision(9) << g[i][n+1] * weight << "\n"; return 0; }
|