#include<iostream>
#include<cstdio>
#include<cstring>
typedef long long ll;
typedef unsigned un;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
ll read()
{
	ll f=1,x=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
	return f*x;
}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
bool umin(int& a,int t){if(t<a)return a=t,1;return 0;}
bool umin(ll& a,ll t){if(t<a)return a=t,1;return 0;}
bool umax(int& a,int t){if(t>a)return a=t,1;return 0;}
bool umax(ll& a,ll t){if(t>a)return a=t,1;return 0;}

#define MAXN 511
bool a[MAXN][MAXN];
char s[MAXN];
int main()
{
	int n=read();
	for(int i=1;i<=n;++i)
	{
		scanf("%s",s+1);
		for(int j=1;j<=n;++j)a[i][j]=(s[j]=='1');
		a[i][i]=1;
	}
	for(int k=1;k<=n;++k)
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)a[i][j]|=(a[i][k]&a[k][j]);
	double ans=0;
	for(int u=1;u<=n;++u)
	{
		int c=0;
		for(int s=1;s<=n;++s)c+=a[s][u];
		ans+=1.00/c;
	}
	printf("%.11lf\n",ans);
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define ll long long
#define VV(t) vector<vector<t>>
using namespace std;
using Graph = VV(int);
const int INF = 1<<29;

int factorial(int n) {
   if (n<=1) return 1;
   else return n*factorial(n-1);
}

int main() {
   int N; cin >> N;
   Graph G(N, vector<int>(N, INF));
   rep(i, N) {
      rep(j, N) {
         char c; cin >> c;
         if (c == '1') G[i][j] = 1;
      }
      G[i][i] = 0;
   }
   rep(k, N) {
      rep(i, N) {
         rep(j, N) {
            G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
         }
      }
   }
   double v = 0;
   rep(i, N) {
      int nonInf = 0;
      rep(j, N) if (G[j][i] < INF/2) nonInf += 1;
      v += (double)1 / nonInf;
   }
   cout << fixed << setprecision(20) << v << endl;
}
