#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define ll long long
#define VV(t) vector<vector<t>>
using namespace std;
using Graph = VV(int);
const int INF = 1<<29;

int factorial(int n) {
   if (n<=1) return 1;
   else return n*factorial(n-1);
}

int main() {
   int N; cin >> N;
   Graph G(N, vector<int>(N, INF));
   rep(i, N) {
      rep(j, N) {
         char c; cin >> c;
         if (c == '1') G[i][j] = 1;
      }
      G[i][i] = 0;
   }
   rep(k, N) {
      rep(i, N) {
         rep(j, N) {
            G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
         }
      }
   }
   double v = 0;
   rep(i, N) {
      int nonInf = 0;
      rep(j, N) if (G[j][i] < INF/2) nonInf += 1;
      v += (double)1 / nonInf;
   }
   cout << fixed << setprecision(20) << v << endl;
}

#include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")
#define int long long int
#define f first
#define s second
#define pb push_back
#define endl '\n'
#define T long double

vector<vector<int>>adj;
bool vis[105];
int cnt[105];

void dfs(int v){
	vis[v]=1;
	cnt[v]++;
	for(auto u:adj[v]){
		if(vis[u]){
			continue;
		}
		dfs(u);
	}
}

main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	char arr[n][n];
	adj.resize(n+1);
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			cin>>arr[i][j];
			if(arr[i][j]=='1'){
				adj[i+1].pb(j+1);
			}
		}
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			vis[j]=0;
		}
		dfs(i);
		
	}
	T ans=0;
	for(int i=1; i<=n; i++){
		ans=ans+(1.0/cnt[i]);
	}
	cout<<setprecision(20)<<ans;
	return 0;
}