#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int N; cin >> N;
	vector<vector<int>> adList(N);
	REP(i, N)
	{
		string S; cin >> S;
		REP(j, N)
		{
			if (S[j] == '1')
			{
				adList[i].push_back(j);
			}
		}
	}
	vector<set<int>> ss(N);
	REP(s, N)
	{
		deque<int> Q{ s };
		vector<bool> arrived(N, false);
		arrived[s] = true;
		while (!Q.empty())
		{
			int t = Q.front(); Q.pop_front();
			ss[t].insert(s);
			for (const int n : adList[t])
			{
				if (arrived[n]) continue;
				Q.push_back(n);
				arrived[n] = true;
			}
		}
	}

	double ans = 0.0;
	REP(s, N)
	{
		const double sv = static_cast<double>(ss[s].size());
		ans += 1.0 / sv;
	}
	cout << setprecision(12) << ans << endl;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define ad(a,b) a=(a+b)%mod;
ll po(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
ll gcd(ll a,ll b){
	return (b?gcd(b,a%b):a);
}
#define X 200010
ll fac[X],ivf[X];
void initfac(){
	fac[0]=1;
	for(ll i=1;i<X;i++)fac[i]=fac[i-1]*i%mod;
	for(ll i=0;i<X;i++)ivf[i]=po(fac[i],mod-2);
}
ll C(ll n,ll k){
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
#define N 110
ll n;
bool s[N][N];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n)rep(j,n){
		char z;
		cin>>z;
		s[i][j]=z-'0';
	}
	rep(i,n)s[i][i]=1;
	rep(k,n)rep(i,n)rep(j,n){
		s[i][j]|=(s[i][k]&s[k][j]);
	}
	double ans=0;
	rep(i,n){
		ll sum=0;
		rep(j,n)if(s[j][i])sum++;
		ans+=1.0/(double)sum;
		cerr<<sum<<endl;
	}
	cout<<fixed<<setprecision(9)<<ans<<endl;
}
