// In the name of god
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef string str;
const ll maxn = 105, inf = 2e18;
ll n, s[maxn];
ld ans, x = 1, y;
bool mark[maxn];
vector <ll> adj[maxn];
void dfs(ll u){
	mark[u] = 1;
	s[u] ++;
	for(ll j : adj[u]){
		if(!mark[j])dfs(j);
	}
}
int main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for(ll i = 1; i <= n; i ++){
		for(ll j = 1; j <= n; j ++){
			char c;
			cin >> c;
			if(c == '1')adj[i].pb(j);
		}
	}
	for(ll i = 1; i <= n; i ++){
		dfs(i);
		memset(mark, 0, sizeof mark);
	}
	for(ll i = 1; i <= n; i ++){
		y = s[i];
		ans += x / y;
	}
	cout << fixed << setprecision(10) << ans << endl;
}

//#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	string S[102];
	int A[102][102];
	scan(N);
	rep(i,N) scan(S[i]);
	fill(A[0],A[N],INF);
	rep(i,N) rep(j,N) if(i==j||S[i][j]=='1') A[i][j]=0;
	rep(k,N){
		rep(i,N){
			rep(j,N){
				if(k==i||k==j) continue;
				if(A[i][j]>A[i][k]+A[k][j]) A[i][j]=A[i][k]+A[k][j];
			}
		}
	}
	int ikeru[101]={};
	rep(i,N){
		rep(j,N){
			if(A[i][j]==0) ikeru[j]++;
		}
	}
	double ans=0;
	rep(i,N) ans+=1.0/ikeru[i];
	prin(setprecision(11)<<ans);
	return 0;
}
