#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#include<functional>
#include<iomanip>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)
#define fps(n) fixed << setprecision(n)
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define eldn endl
#define elnd endl
#define icn cin
#define cotu cout
#define Endl endl
#define EE endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
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(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n; cin >> n;
    double ans = 0.0;
    reps(i,1,n-1){
        ans += (double)n * (1 / (double)i);
    }
    cout << fps(20) << ans << EE;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++) 
int main(){
  int N;cin>>N;
  string S[N];
  rep(i,N)cin>>S[i];
  vector<vector<int>> D(N,vector<int>(N,1e5));
  rep(i,N){
    rep(j,N){
      if(i==j)D[i][j]=0;
      if(S[i][j]=='1')D[j][i]=1;
    }
  }
  rep(k,N){
    rep(i,N){
      rep(j,N){
        D[i][j]=min(D[i][j],D[i][k]+D[k][j]);
      }
    }
  }
  double ans=0,t; 
  rep(i,N){
    t=0;
    rep(j,N)if(D[i][j]!=1e5)t++;
    ans+=1/t;
  }
  cout<<fixed<<setprecision(9)<<ans;
}
