#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin>>N;
  vector<string> S(N);
  rep(i,N) cin>>S[i];

  vector<vector<int>> D(N,vector<int> (N,0));
  rep(i,N) rep(j,N) D[i][j]=S[i][j]-'0';
  rep(i,N) D[i][i]=1;

  for(int k=0;k<N;k++){
    for(int i=0;i<N;i++) for(int j=0;j<N;j++){
      if(D[i][k]&&D[k][j]) D[i][j]=1;
    }
  }

  vector<int> num(N,0);
  rep(i,N) rep(j,N) num[j]+=D[i][j];

  double ans=0.0;
  rep(i,N) ans+=1.0/(double)num[i];

  cout<<fixed<<setprecision(15)<<ans<<endl;

  return 0;
}

#include <bits/stdc++.h>
#define N 105
using namespace std;

template <typename T>
inline void read(T &num) {
    T x = 0, f = 1; char ch = getchar();
    for (; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') f = -1;
    for (; ch <= '9' && ch >= '0'; ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ '0');
    num = x * f;
}

int n, e[N][N], cnt[N];
long double ans;
bool vis[N];

void dfs(int x) {
    vis[x] = 1; cnt[x]++;
    for (int i = 1; i <= n; i++) {
        if (e[x][i] && !vis[i]) dfs(i);
    }
}

long double calc(int x) {
    long double res = x * 1.0 / (x+1);
    return res;
}

int main() {
 //   freopen("1.in", "r", stdin);
    read(n); ans = n;
    for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) {
        scanf("%1d", &e[i][j]);
    }
    for (int i = 1; i <= n; i++) {
        memset(vis, 0, sizeof(vis));
        dfs(i); cnt[i]--;
    }
    for (int i = 1; i <= n; i++) {
        long double now = calc(cnt[i]);
        ans -= now;
    }
    printf("%.20Lf\n", ans);
    return 0;
}