HNOI2013 get!
Gaussian elimination calculates the expectation of the number of times each point passes, and then the expectation of each edge is calculated
Then set the sorting principle, disorderly and minimal
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <
Cmath> using namespace std;
#define DOUBLE long double const int n=500+5;
const double eps=1e-9;
Double G[n][n];
void Gauss (int n) {for (int i=1;i<=n;i++) {int J;
for (j=i;j<=n;j++) if (Fabs (G[j][i]) >eps) break;
for (int k=i;k<=n;k++) swap (g[i][k],g[j][k]);
for (j=i+1;j<=n;j++) {double t=g[j][i]/g[i][i];
for (int k=i;k<=n+1;k++) g[j][k]-=t*g[i][k];
}} for (int i=n;i>=1;i--) {for (int j=i+1;j<=n;j++) G[I][N+1]-=G[J][N+1]*G[I][J];
G[i][n+1]/=g[i][i];
}} bool E[n][n];
Double Deg[n];
Double Path[n*n];
int main () {//freopen ("a.in", "R", stdin);
int n,m;scanf ("%d%d", &n,&m);
while (m--) {int u,v;scanf ("%d%d", &u,&v);
E[u][v]=e[v][u]=1;
deg[u]+=1.0;deg[v]+=1.0;
} for (int i=1;i<=n;i++) {g[i][i]=1.0;
for (int j=1;j<=n;j++) if (E[j][i]) g[i][j]-=1.0/deg[j];
g[i][n]=0.0;
} g[n][n]=0.0;g[1][n]=1.0; Gauss (N-1);
Double ans=0.0;
int tot=0;
for (int i=1;i<=n;i++) for (int j=i+1;j<=n;j++) if (E[i][j]) path[++tot]=g[i][n]/deg[i]+g[j][n]/deg[j];
Sort (path+1,path+1+tot);
for (int i=1;i<=tot;i++) ans+=path[i]* (tot-i+1);
printf ("%.3lf\n", ans);
return 0; }