//#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;


#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9+7; //998244353;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

//using mint = modint1000000007;

vector<int> tpl_sort(vector<vector<int>>& r){
	int n= r.size();
	vector<int> rt, cnt(n); rt.reserve(n+2);
	for(auto& xl: r) for(auto x: xl) cnt[x]++;
	queue<int> qu;
	for(int i=0; i<n; i++) if(cnt[i]==0) qu.emplace(i);
	while(!qu.empty()){
		auto cr = qu.front(); qu.pop();
		rt.emplace_back(cr);
		for(auto x: r[cr]) if(--cnt[x] == 0) qu.emplace(x);
	}
	return rt;
}



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n ;
	vector<string> s(n);
	rep(i, n) cin >>s[i];
	
	vector<VI> r(n);
	vector<set<int>> tc(n);
	rep(i, n) rep(j,n) if(s[i][j]=='1') r[i].push_back(j);
	VI ct(n);
	
	auto rec=[&](auto rec, int c, const int p)->void{
		for(auto x: r[c]) if(!tc[p].count(x)){
			if(x==p) continue;
			tc[p].insert(x);
			rec(rec, x, p);
		}
	};
	rep(i, n) rec(rec, i, i);

	rep(i, n){
		//dbg(i,"::");for(auto x :tc[i]) cerr<<x<<" "; dbg();
		for(auto x :tc[i]) ct[x]++;
	}
	//for(auto x :ct) cerr<<x<<" "; dbg();
	double ans =0;
	rep(i, n) ans += 1.0 / (ct[i]+1);
	printf("%.16f\n", ans);
	return 0;
}

#include <algorithm>
#include <array>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


int main() {
    cout << setprecision(16);

    int N;
    cin >> N;
    vector<string> S(N);

    for (auto &s : S)
        cin >> s;

    for (int k = 0; k < N; k++)
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                if (S[i][k] == '1' && S[k][j] == '1')
                    S[i][j] = '1';

    double answer = 0;

    for (int i = 0; i < N; i++) {
        int other = 0;

        for (int j = 0; j < N; j++)
            other += i != j && S[j][i] == '1';

        answer += 1.0 / (other + 1);
    }

    cout << answer << '\n';
}
