#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define m_p make_pair
#define sz(x) (int)x.size()
#define out(x) cerr<<#x<<" = "<<x<<" "
#define outln(x) cerr<<#x<<" = "<<x<<endl
#define outarr(x,l,r) cerr<<#x"["<<l<<"-"<<r<<"] = "; for (int _i=l;_i<=r;++_i) cerr<<x[_i]<<" ";cerr<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define gc() getchar()
//char buf[1<<23],*p1=buf,*p2=buf;
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <class T> void read(T &x)
{
    x=0; char c=gc(); int flag=0;
    while (c<'0'||c>'9') flag|=(c=='-'),c=gc();
    while (c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=gc();
    if (flag) x=-x;
}
template <class T> inline T _max(T a,T b){return a>b ? a : b;}
template <class T> inline T _min(T a,T b){return a<b ? a : b;}
template <class T> inline bool checkmax(T &a,T b){return b>a ? a=b,1 : 0;}
template <class T> inline bool checkmin(T &a,T b){return b<a ? a=b,1 : 0;}
const int N=105,inf=0x3f3f3f3f;
int n;
int g[N][N];
int d[N];
char mp[N];
void init()
{
	read(n);
	for (int i=1;i<=n;++i)
	{
		scanf("%s",mp+1);
		for (int j=1;j<=n;++j)
		{
			g[i][j]=(i==j ? 0 : inf);
			if (mp[j]=='1') g[i][j]=1;
		}
	}
	for (int k=1;k<=n;++k)
		for (int i=1;i<=n;++i)
			for (int j=1;j<=n;++j)
				if (g[i][k]<inf&&g[k][j]<inf)
					checkmin(g[i][j],g[i][k]+g[k][j]);
	for (int i=1;i<=n;++i)
		for (int j=1;j<=n;++j)
			if (g[j][i]<inf) ++d[i];
}

void solve()
{
	double ans=0;
	for (int i=1;i<=n;++i) ans+=1.0/d[i];
	printf("%.12lf\n",ans);
}

int main()
{
	init();
	solve();
	return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e18;
//const ll mod = 1000000007;
ll dist[105][105];
ll N;
string S[105];
long double ans;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> S[i];
        for(int j = 0; j < N; j++) {
            if(S[i][j] == '1') dist[i][j] = 1;
            else dist[i][j] = INF;
        }
        dist[i][i] = 0;
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            for(int k = 0; k < N; k++) {
                chmin(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
    for(int i = 0; i < N; i++) {
        //cerr << "---" << i << "---" << endl;
        ll num = 0;
        for(int j = 0; j < N; j++) {
            if(dist[j][i] < INF) {
                //cerr << j << endl;
                num++;
            }
        }
        ans += (long double)1 / num;
    }
    cout << fixed << setprecision(30) << ans << endl;
    return 0;
}
