The probability of reaching another point is the probability that the point cannot be reached.

Walk

**Time Limit: 30000/15000 MS (Java/others) memory limit: 65536/65536 K (Java/Others)**

Total submission (s): 51 accepted submission (s): 37

Special Judge
Problem descriptioni used to think I cocould be anything, but now I know that I couldn't do anything. So I started traveling.

The nation looks like a connected bidirectional graph, and I am randomly walking on it. it means when I am at node I, I will travel to an adjacent node with the same probability in the next step. I will pick up the Start Node randomly (each node in the graph has the same probability .), and travel for D Steps, noting that I may go through some nodes multiple times.

If I miss some sights at a node, it will make me unhappy. So I wonder for each node, what is the probability that my path doesn' t contain it.

Inputthe first line contains an integer T, denoting the number of the test cases.

For each test case, the first line contains 3 integers n, m and D, denoting the number of vertices, the number of edges and the number of steps respectively. then M lines follows, each containing two integers A and B, denoting there is an edge between node A and Node B.

T <= 20, n <= 50, n-1 <= m <= N * (n-1)/2, 1 <= d <= 10000. there is no self-loops or multiple edges in the graph, and the graph is connected. the nodes are indexed from 1.

Outputfor each test cases, output n lines, the I-th line containing the desired probability for the I-th node.

Your answer will be accepted if its absolute error doesn't exceed 1e-5.

Sample Input

25 10 1001 22 33 44 51 52 43 52 51 41 310 10 101 22 33 44 55 66 77 88 99 104 9

Sample output

0.00000000000.00000000000.00000000000.00000000000.00000000000.69933179670.58642849520.44408608210.22758969910.42940745910.48510487420.48960188420.45250442500.34065674830.6421630037

Source2014 ACM/ICPC Asia Regional Anshan online

#include <algorithm>#include <iostream>#include <stdlib.h>#include <string.h>#include <iomanip>#include <stdio.h>#include <string>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>#define eps 1e-12///#define M 1000100#define LL __int64///#define LL long long///#define INF 0x7ffffff#define INF 0x3f3f3f3f#define PI 3.1415926535898#define zero(x) ((fabs(x)<eps)?0:x)using namespace std;const int maxn = 10010;double dp[55][maxn];double ans[55];vector<int>g[55];int main(){ int T; cin >>T; while(T--) { int n, m, d; scanf("%d %d %d",&n, &m, &d); for(int i = 1; i <= n; i++) g[i].clear(); int x, y; for(int i = 1; i <= m; i++) { scanf("%d %d",&x, &y); g[x].push_back(y); g[y].push_back(x); } for(int p = 1; p <= n; p++) { memset(dp, 0, sizeof(dp)); for(int i = 1; i <= n; i++) dp[i][0] = 1.0/n; for(int i = 0; i < d; i++) { for(int j = 1; j <= n; j++) { if(j == p) continue; int N = g[j].size(); for(int k = 0; k < N; k++) { int u = g[j][k]; dp[u][i+1] += dp[j][i]*(1.0/N); } } } ans[p] = 0.0; for(int i = 1; i <= n; i++) { if(i == p) continue; ans[p] += dp[i][d]; } printf("%.9lf\n",ans[p]); } } return 0;}

HDU 5001 walk (violent)