Test instructions: An undirected connected graph with vertices numbered from 1 to n, and edges numbered from 1 to M. Small Z takes a random walk on the graph, initially small z at Vertex 1th, each step small z randomly selects an edge of the current vertex at an equal probability, and goes along this edge to the next vertex to get a number equal to this edge. When small z reaches the n vertex, the walk ends and the total score is the sum of all the points obtained. Now, please number the M-edge, so that small z obtains the lowest total value.
Idea: Obviously, you need to ask for each side of the expected number of times, and then sort the greedy assignment, but what is the expected number of each edge?
is E (e) =e (U)/d (U) + E (v)/d (v) (u,v∈e)
So the practice is to first find out the number of expectations of each point, also, for the Nth point, its expectations in the final statistics when the time to be considered as 0, because the n point will not come out again.
1#include <algorithm>2#include <cstdio>3#include <cmath>4#include <cstring>5#include <iostream>6 structedge{7 intu,v;8 DoubleW;9}e[500005];Ten intn,m,du[500005],go[1005][1005]; One Doublea[1010][1010],p[500005]; A BOOLCmp (Edge Q,edge W) { - returnQ.w>W.W; - } the voidGauss () { - intto,now=1; - for(intI=1; i<=n;i++){ - for(to=now;to<=n;to++)if(a[to][i]!=0) Break; + if(to>n)Continue; - if(To!=now) for(intj=1; j<=n+1; j + +) Std::swap (A[now][j],a[to][j]); + Doublet=A[now][i]; A for(intj=1; j<=n+1; j + +) a[now][j]/=T; at for(intj=1; j<=n;j++) - if(j!=Now ) { -t=A[j][i]; - for(intk=1; k<=n+1; k++) -a[j][k]-=t*A[now][k]; - } innow++; - } to } + intMain () { -scanf"%d%d",&n,&m); the inttot=0; * for(intI=1; i<=m;i++){ $ intx, y;Panax Notoginsengscanf"%d%d",&x,&y); - if(x==y)Continue; thee[++tot].u=x;e[tot].v=y; +go[x][++go[x][0]]=y; Ago[y][++go[y][0]]=x; thedu[e[tot].u]++; +du[e[tot].v]++; - } $m=tot; $ for(intI=1; i<n;i++) a[i][i]=1; - for(intI=1; i<n;i++){ - for(intj=1; j<=go[i][0];j++){ the intt=Go[i][j]; - if(t==n)Continue;Wuyia[i][t]-=1.0/Du[t]; the } - } Wun--; -a[1][n+1]=1; About Gauss (); $ for(intI=1; i<=n;i++) p[i]=a[i][n+1]; - for(intI=1; i<=m;i++) -E[i].w= ((Double) (p[e[i].u])/((Double) du[e[i].u]) + ((Double) (P[E[I].V])/((Double) du[e[i].v]); -Std::sort (e+1, e+1+m,cmp); A Doubleans=0; + for(intI=1; i<=m;i++) ans+=e[i].w*i; theprintf"%.3f\n", ans); -}
Bzoj 3143 Walk (Gaussian elimination)