#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	bool A[110][110] = {}; 
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			char c; cin >> c; A[i][j] = c - '0'; 
		}	
	}
	double ans = 0; 
	for(int i = 0; i < N; i++){
		bool ok[110] = {}; 
		ok[i] = true; 
		queue<int> que; 
		que.push(i); 
		while(que.size()){
			int p = que.front(); 
			que.pop(); 
			for(int i = 0; i < N; i++){
				if(A[i][p] && !ok[i]){
					ok[i] = true; que.push(i); 
				}
			}
		}
		int cnt = 0; 
		for(int i = 0; i < N; i++){
			if(ok[i]) cnt ++; 
		}
		ans += (double) 1.0 / cnt; 
	}
	cout.precision(15); 
	cout << ans << "\n"; 
}
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define FORD(i, a, b) for (int i=(a); i>(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define SZ(x) ((int)(x).size())
#define HASK(S, x) (S.find(x) != S.end())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

typedef pair <int, int> PII;
template <typename T1, typename T2> inline void remin(T1& a, T2 b) { a = min(a, (T1)b);	}

const int maxN = 123;

int n, vis[maxN], cnt[maxN], visCtr;
char G[maxN][maxN];

void dfs(int v)
{
	vis[v] = visCtr;
	cnt[v]++;
	FOR(u, 1, n+1)
		if (G[v][u] == '1' and vis[u] != visCtr)
			dfs(u);
}

void solve()
{
	scanf ("%d", &n);
	
	FOR(i, 1, n+1)
		scanf ("%s", &G[i][1]);
	FOR(i, 1, n+1)
	{
		visCtr = i;
		dfs(i);
	}
	long double res = 0;
	FOR(i, 1, n+1)
		res += 1.0 / cnt[i];
	printf("%.13Lf\n", res);
}
 
int main()
{		
	int t = 1;
	//scanf ("%d", &t);
	FOR(tid, 1, t+1)
	{
		//printf("Case #%d: ", tid);
		solve();
	}
	return 0;
}
