题解:
既然等概率又收敛,多跑一百次就是答案了。
#include <bits/stdc++.h>
using namespace std;
int n,m,k;
const int N=100+10;
double f[N][N];
vector<int> g[N];
void solve() {
int n,m;
while(~scanf("%d%d",&n,&m)) {
for (int i = 1; i <= n; i++) g[i].clear(),g[i].push_back(i);
for (int i = 1; i <= m; i++) {
int a, b;
scanf("%d%d", &a, &b);
g[a].push_back(b);
}
memset(f,0,sizeof f);
f[0][1] = 1;
for (int i = 1; i <= 100; i++) {
for (int j = 1; j <= n; j++) {
for (auto k:g[j]) {
f[i][k] += f[i - 1][j] * (1.0 / (g[j].size()));
}
}
}
double res = 0;
for (int i = 1; i <= n; i++) res = max(f[100][i], res);
cout << res << '\n';
}
}
signed main()
{
solve();
}