#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,dp[100][100];
double cnt,ans;
string s[100],t;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        for(int j=0;j<n;j++){
            if(i==j)dp[i][j]=0;
            else if(s[i][j]=='0')dp[i][j]=1e9;
            else dp[i][j]=1;
        }
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i==j)continue;
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }
    for(int i=0;i<n;i++){
        cnt=1.0;
        for(int j=0;j<n;j++){
            if(dp[j][i]!=0&&dp[j][i]!=1e9)cnt+=1.0;
        }
        ans+=1/cnt;
    }
    cout<<setprecision(15)<<ans<<endl;
}

#include<bits/stdc++.h>

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
typedef long double Lf;
typedef pair<int, int> pii;

const int maxn = 105;

int n;
Lf ans;
int reach[maxn][maxn];
char s[maxn];

int main(){
	scanf("%d", &n);

	FOR(i, 0, n){
		char buf[maxn]; scanf("%s", buf);
		FOR(j, 0, n)
			reach[i][j] = buf[j] - '0';
		reach[i][i] = 1;
	}
	
	FOR(k, 0, n) FOR(i, 0, n) FOR(j, 0, n)
		reach[i][j] |= (reach[i][k] & reach[k][j]);
		
	FOR(i, 0, n){
		int cnt = 0;
		FOR(j, 0, n)
			cnt += reach[j][i];
		ans += (Lf)1.0 / cnt;
	}
	
	printf("%.15Lf\n", ans);
	return 0;
}
