[AGC049A] Erasing Vertices 题解
对于任意的一个点
考虑如何计算
我们可以先在 bitset 的优化下处理每个点能够到达的点,然后对于每一个点枚举并计算能够到达它的点,就可以算出
对于 CF280C 这道题,只要把上述
AC Code:
#include <bits/stdc++.h>
using namespace std;
namespace Slongod{
const int N = 107;
bitset <N> g[N];
int n; long double ans;
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
char c; cin >> c;
g[i][j] = c - '0';
}
g[i][i] = 1;
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (g[j][i])
g[j] |= g[i];
}
}
for (int i = 1; i <= n; i++)
{
int sz = 0;
for (int j = 1; j <= n; j++)
{
if (g[j][i])
sz++;
}
ans = ans + 1.0 / sz;
}
cout << fixed << setprecision(14) << ans << '\n';
return 0;
}
}int main()
{
ios :: sync_with_stdio(0);
cin.tie(0) , cout.tie(0);
return Slongod :: main();
}