#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 rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
constexpr int inf=1000001000;
constexpr ll INF=2e18;
constexpr ll mod=1000000007;
// ll MOD=998244353;
constexpr ll MOD=998244353;

int main() {
    int n;
    cin >> n;
    vector<int> a(n,0);
    vector<vector<int>> e(n,vector<int>(0));
    rep(i,n){
        string s;
        cin >> s;
        rep(j,n){
            if (s[j]=='1') e[i].push_back(j);
        }
    }
    rep(i,n){
        vector<int> b(n,0);
        b[i]=1;
        queue<int> q;
        q.push(i);
        while(!q.empty()){
            int f=q.front();
            q.pop();
            rep(j,e[f].size()){
                if (b[e[f][j]]!=1){
                    b[e[f][j]]=1;
                    q.push(e[f][j]);
                }
            }
        }
        rep(j,n){
            a[j]+=b[j];
        }
    }
    ld ans=0;
    rep(i,n){
        ld w=a[i],ww=1;
        ans+=(ww/a[i]);
    }
    cout << fixed << setprecision(10) << ans << endl;
}
