# solution

$f[i]$表示$i$这个点被经过的次数。那么就有$f[u]=\sum\limits_{w(u,v)}^n \frac{f[v]}{du[v]}$

# code

/*
* @Author: wxyww
* @Date:   2020-04-27 20:14:39
*/
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<ctime>
using namespace std;
typedef long long ll;
const int N = 510;
ll x = 0,f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1; c = getchar();
}
while(c >= '0' && c <= '9') {
x = x * 10 + c - '0'; c = getchar();
}
return x * f;
}
struct node {
int v,nxt;
}e[N * N];
}
double a[N][N];
int du[N];
void Guass(int n) {
for(int i = 1;i <= n;++i) {
int t = i;
for(int j = i + 1;j <= n;++j)
if(a[j][i] > a[t][i]) t = j;

if(fabs(a[t][i]) < 1e-8) continue;
swap(a[t],a[i]);

double div = a[i][i];
for(int j = i;j <= n + 1;++j) a[i][j] /= div;

for(int j = 1;j <= n;++j) {
if(j == i) continue;
div = a[j][i];
for(int k = i;k <= n + 1;++k)
a[j][k] -= div * a[i][k];
}
}
}

double ans[N * N];
int tot;
int main() {
for(int i = 1;i <= m;++i) {
du[u]++;du[v]++;
}

a[1][n] = 1;

for(int u = 1;u < n;++u) {
a[u][u] = 1;
for(int i = head[u];i;i = e[i].nxt ) {
int v = e[i].v;
if(v == n) continue;
a[u][v] -= 1.0 / du[v];
}
}

Guass(n - 1);

for(int i = 2;i <= ejs;i += 2)
ans[++tot] = a[e[i].v][n] / du[e[i].v] + a[e[i ^ 1].v][n] / du[e[i ^1].v];

sort(ans + 1,ans + tot + 1);
double anss = 0;
for(int i = 1;i <= tot;++i)
anss += ans[i] * (tot - i + 1);

printf("%.3lf\n",anss);
return 0;
}

posted @ 2020-04-27 20:43  wxyww  阅读(...)  评论(...编辑  收藏