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

#define fi first
#define se second

typedef long long ll;
typedef pair<int,int> ii;

const int N = 1e2;
int n;
bool vis[N+2];
vector<int> adj[N+2];

int dfs(int cur) {
    vis[cur] = 1;
    int ret = 1;
    for (int nx : adj[cur]) {
        if (!vis[nx])
            ret += dfs(nx);
    }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            char x; cin >> x;
            if (x == '1')
                adj[j].push_back(i);
        }
    }
    double ans = 0;
    for (int i = 1; i <= n; i++) {
        memset(vis,0,sizeof(vis));
        ans += 1.0 * 1/dfs(i);
    }
    cout << fixed << setprecision(20);
    cout << ans << '\n';
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
struct UnionFind {
private:
    vector<int> par;
    vector<int> count;
    vector<int> rank;
public:
    UnionFind(int N) {
        count.assign(N, 1);
        rank.assign(N, 0);
        par.assign(N, 0);
        rep(i, N) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x)
            return x;
        else {
            par[x] = root(par[x]);
            return par[x];
        }
    }

    void unite(int x, int y) {
        x = root(x), y = root(y);
        if (x == y) return;
        if (rank[x] < rank[y])
            swap(x, y);
        else if (rank[x] == rank[y])
            rank[y]++;
        par[y] = x;
        count[x] += count[y];
        return;
    }

    int size(int x) {
        return count[root(x)];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }
};
using UF = struct UnionFind;

int main() {
    ll N;
    cin >> N;
    vc<string> S(N);
    rep(i, N) cin >> S[i];

    vvc<int> child(N), parent(N);
    rep(i, N){
        vl srch(N);
        srch[i] = true, child[i].eb(i);
        queue<ll> q;
        q.emplace(i);
        while(!q.empty()){
            ll now = q.front();
            q.pop();
            rep(j, N){
                if (srch[j] or S[now][j] == '0') continue;
                srch[j] = true;
                child[i].eb(j);
                q.emplace(j);
            }
        }
        srch = vl(N), q.emplace(i), parent[i].eb(i), srch[i] = true;
        while(!q.empty()){
            ll now = q.front();
            q.pop();
            rep(j, N){
                if (srch[j] or S[j][now] == '0') continue;
                srch[j] = true;
                parent[i].eb(j);
                q.emplace(j);
            }
        }
    }

    ld ans = 0;
    rep(i, N) ans += 1.0L / parent[i].size();

    cout << ans << endl;
}