#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define Endl endl
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18

using namespace std;

typedef long long llint;
typedef pair<llint, llint> P;

llint n;
vector<int> G[105];
bool used[105];

llint dfs(int v)
{
	used[v] = true;
	llint ret = 1;
	for(auto u : G[v]){
		if(!used[u]) ret += dfs(u);
	}
	return ret;
}

int main(void)
{
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	
	cin >> n;
	
	char c;
	rep(i, 1, n){
		rep(j, 1, n){
			cin >> c;
			if(c%2) G[j].push_back(i);
		}
	}
	
	double ans = 0;
	rep(i, 1, n){
		rep(j, 1, n) used[j] = false;
		ans += 1.0 / dfs(i);
	}
	printf("%.11f\n", ans);
	
	return 0;
}
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <vector>

#define TRACE(x) std::cout << #x << " = " << x << "\n"
#define _ << " _ " <<

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);
  int N;
  cin >> N;

  vector<vector<int>> r(N, vector<int>(N, 0));
  for (int i = 0; i < N; ++i) {
    string A;
    cin >> A;
    for (int j = 0; j < N; ++j)
      if (A[j] == '1') r[i][j] = 1;
    r[i][i] = 1;
  }

  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        r[i][j] |= r[i][k] & r[k][j];
      }
    }
  }

  double ret = 0;
  for (int i = 0; i < N; ++i) {
    int cnt = 0;
    for (int j = 0; j < N; ++j) cnt += r[j][i];
    ret += 1.0 / cnt;
  }

  cout << std::setprecision(15) << ret << '\n';
  return 0;
}
