#include<bits/stdc++.h> #define ll long long #define db double #define gc getchar #define pc putchar #define pb push_back
usingnamespace std;
namespace IO { template <typename T> voidread(T &x) { x = 0; bool f = 0; char c = gc(); while(!isdigit(c)) f |= c == '-', c = gc(); while(isdigit(c)) x = x * 10 + c - '0', c = gc(); if(f) x = -x; }
#include<bits/stdc++.h> #define int long long #define db double #define gc getchar #define pc putchar #define pb push_back #define fi first #define se second #define INF 1e18
usingnamespace std;
namespace IO { template <typename T> voidread(T &x) { x = 0; bool f = 0; char c = gc(); while(!isdigit(c)) f |= c == '-', c = gc(); while(isdigit(c)) x = x * 10 + c - '0', c = gc(); if(f) x = -x; }
#include<bits/stdc++.h> #define ll long long #define db double #define gc getchar #define pc putchar #define pb push_back
usingnamespace std;
namespace IO { template <typename T> voidread(T &x) { x = 0; bool f = 0; char c = gc(); while(!isdigit(c)) f |= c == '-', c = gc(); while(isdigit(c)) x = x * 10 + c - '0', c = gc(); if(f) x = -x; }
#include<bits/stdc++.h> #define ll long long #define db double #define gc getchar #define pc putchar #define pb push_back
usingnamespace std;
namespace IO { template <typename T> voidread(T &x) { x = 0; bool f = 0; char c = gc(); while(!isdigit(c)) f |= c == '-', c = gc(); while(isdigit(c)) x = x * 10 + c - '0', c = gc(); if(f) x = -x; }
int n, m = 50; db p, a[N][N], b[N][N]; db f[N][N];
structMatrix { db mat[N][N]; Matrix() {memset(mat, 0, sizeof(mat));}
Matrix operator * (const Matrix &b) const { Matrix a; for(int i = 0; i <= m; i++) for(int j = 0; j <= m; j++) for(int k = 0; k <= m; k++) a.mat[i][j] += mat[i][k] * b.mat[k][j]; return a; }
Matrix operator ^ (int b) { Matrix a, res; memcpy(a.mat, mat, sizeof(mat)); for(int i = 0; i <= m; i++) res.mat[i][i] = 1; for(; b; a = a * a, b >>= 1) if(b & 1) res = res * a; return res; } } A, B;
intmain() { read(n, p); p /= 1e9; a[1][1] = p, a[1][2] = b[1][2] = 1 - p; for(int i = 2; i <= m; i++) { a[i][1] = p, a[i][2] = 1 - p + p * p, b[i][2] = 1 - p; for(int j = 3; j <= m; j++) { a[i][j] = a[i - 1][j - 1] * a[i][j - 1]; b[i][j] = a[i - 1][j - 1] * b[i][j - 1]; } } for(int i = m; i >= 1; i--) for(int j = 1; j <= m; j++) { a[i][j] *= (1.0 - a[i - 1][j]); b[i][j] *= (1.0 - a[i - 1][j]); } f[1][1] = 1, f[1][2] = 2; for(int i = 2; i <= m; i++) { db sum = 0; for(int j = 2; j <= m; j++) f[i][1] += f[i - 1][j] * b[i - 1][j], sum += b[i - 1][j]; f[i][1] = f[i][1] / sum + 1; for(int j = 2; j <= m; j++) { sum = 0; for(int k = 1; k < j; k++) f[i][j] += f[i - 1][k] * a[i - 1][k], sum += a[i - 1][k]; f[i][j] = f[i][j] / sum + j; } } if(n <= m) { db ans = 0; for(int i = 1; i <= m; i++) ans += a[n][i] * f[n][i]; printf("%.8lf\n", ans); return0; } A.mat[0][0] = 1; for(int i = 1; i <= m; i++) A.mat[0][i] = f[m][i]; db sum = 0; B.mat[0][0] = B.mat[0][1] = 1; for(int i = 2; i <= m; i++) B.mat[i][1] += b[m][i], sum += b[m][i]; for(int i = 2; i <= m; i++) B.mat[i][1] /= sum; for(int j = 2; j <= m; j++) { sum = 0; for(int i = 1; i < j; i++) B.mat[i][j] += a[m][i], sum += a[m][i]; for(int i = 1; i < j; i++) B.mat[i][j] /= sum; B.mat[0][j] = j; } A = A * (B ^ (n - m)); db ans = 0; for(int i = 1; i <= m; i++) ans += a[m][i] * A.mat[0][i]; printf("%.8lf\n", ans); return0; } // A.S.
#include<bits/stdc++.h> #define ll long long #define db double #define gc getchar #define pc putchar #define pb push_back
usingnamespace std;
namespace IO { template <typename T> voidread(T &x) { x = 0; bool f = 0; char c = gc(); while(!isdigit(c)) f |= c == '-', c = gc(); while(isdigit(c)) x = x * 10 + c - '0', c = gc(); if(f) x = -x; }
Matrix operator ^ (int b) { Matrix a, res; res.n = n, res.init(); a.n = n, memcpy(a.mat, mat, sizeof(mat)); while(b) { if(b & 1) res = res * a; a = a * a, b >>= 1; } return res; } } A, B;
intmain() { read(n, m, k); for(int i = 1; i <= n; i++) { read(flag[i]); if(flag[i]) id[++tot] = i; } for(int i = 1, u, v; i <= m; i++) read(u, v), g[u][v]++, g[v][u]++, deg[u]++, deg[v]++;