#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;
}

// Coder: @SumitRaut
#include <bits/stdc++.h>
#define speedup ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr),cout.precision(16)
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
#define sbc __builtin_popcount
#define pb push_back
#define em emplace
#define emb emplace_back
#define ff first
#define ss second
#define ll long long
const ll mod = 1e9+7;

template<typename T> void smax(T& a, T b) { if(a<b) a=b; }
template<typename T> void smin(T& a, T b) { if(a>b) a=b; }
template<typename T> T pw(T a,T b) { T p=1,one=1; while(b) { if(b&one) p=p*a; a=a*a; b >>=1; } return p; }
template<typename T> T pwm(T a,T b,T md=mod) { T p=1,one=1; while(b) { if(b&one) p=p*a%md; a=a*a%md; b >>=1; } return p; }

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
	for(auto& it:v)
		is>>it;
	return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto &it : v)
		os << it << ' ';
	return os;
}

#ifndef ONLINE_JUDGE
class Timer { chrono::high_resolution_clock::time_point start_t, end_t; public: Timer() { start_t=chrono::high_resolution_clock::now(); } ~Timer() { end_t = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(end_t-start_t); cerr<<"\nRunTime: "<<duration.count()<<"ms"<<'\n'; } };
void debug() { cerr << '\n'; }
template <typename T, typename... Args>
void debug(T print, Args... args) { cerr << ' ' << print; debug(args...); }
#define deb(...) cerr << "[" << #__VA_ARGS__ << "]" << " --> ", debug(__VA_ARGS__)
#else
#define deb(...) void(0)
#endif

const int inf=1e8;
vector<int> cnt;
void bfs(int v, vector <int> &d, vector<vector<int>>& g) {
    queue<int> Qu;
    Qu.push(v);
    d[v] = 0;
    while (!Qu.empty()) {
        auto tmp = Qu.front();
        Qu.pop();
        ++cnt[tmp];
        for (auto &it:g[tmp]) {
            if (d[it] == inf) {
                d[it] = d[tmp] + 1;
                Qu.push(it);
            }
        }
    }
}

void solve() {
	int n;
	cin>>n;
	vector<vector<int>> g(n);
	cnt.assign(n,0);
	for(int i=0;i<n;++i) {
		string s;
		cin>>s;
		for(int j=0;j<n;++j)
			if(s[j]=='1')
				g[i].pb(j);
	}
	for(int i=0;i<n;++i) {
		vector<int> d(n,inf);
		bfs(i,d,g);
	}
	double ans=0.0;
	for(auto& it:cnt)
		ans+=1.0/it;
	cout<<ans<<endl;
}

int main() {
	#ifndef ONLINE_JUDGE
	Timer timer;
	#endif
	speedup;
	//int t; cin>>t; while(t--)
	solve();
}
