#include<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<bitset<100>> edge(N);
    for(unsigned long i{0}; i < N; ++i){
        string S;
        cin >> S;
        for(unsigned long j{0}; j < N; ++j)edge[j][i] = (S[j] == '1');
        edge[i][i] = true;
    }
    for(unsigned long i{0}; i < N; ++i)for(auto& j : edge)for(unsigned long k{0}; k < N; ++k)if(j[k])j |= edge[k];
    long double ans{0};
    for(const auto& i : edge)ans += 1.0L / i.count();
    cout << fixed << setprecision(15) << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

const int N=101;

int n,g[N][N],C[N][N],vis[N],to[N];

char s[N][N];

void dfs(int x)
{
    if(vis[x])
        return;
    vis[x]=1;
    for(int i=1;i<=n;i++)
        if(g[x][i])
            dfs(i);
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            g[i][j]=s[i][j]-'0';
    for(int i=1;i<=n;i++)
    {
        fill(vis+1,vis+n+1,0);
        dfs(i);
        for(int j=1;j<=n;j++)
            to[j]+=vis[j];
    }
    double ans=0;
    for(int i=1;i<=n;i++)
        ans+=1.0/to[i];
    printf("%.10lf\n",ans);
}