#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,b,a) for(int i=b;i>=a;i--)
#define efo(i,u,v) for(int i=BB[u],v=B[BB[u]][1];i;v=B[i=B[i][0]][1])
#define mset(a,x) memset(a,x,sizeof(a))
template<typename T> bool chkmin(T &a,const T &b) {return b<a?a=b,1:0;}
template<typename T> bool chkmax(T &a,const T &b) {return b>a?a=b,1:0;}
using namespace std;
typedef long long ll;
typedef double db;
char ch;
int read(){int n=0,p=1;for(ch=getchar();ch<'0' || '9'<ch;ch=getchar())if(ch=='-') p=-1;for(;'0'<=ch && ch<='9';ch=getchar()) n=n*10+ch-'0';return n*p;}
const int N=105;
int n,a[N][N],fa[N],sz[N];
int getfa(int x)
{
	if(!fa[x]) return x;
	fa[x]=getfa(fa[x]);
	return fa[x];
}
bool vis[N],insta[N];
int sta[N],cnt[N];
void mrg(int x,int y)
{
	int fx=getfa(x),fy=getfa(y);
	if(fx==fy) return;
	fa[fy]=fx;
	sz[fx]+=sz[fy],sz[fy]=0;
}
void dfs(int x)
{
	if(vis[x])
	{
		if(insta[x])
		for(int i=sta[0];sta[i]!=x;i--)
			mrg(sta[i],x);
		return;
	}
	sta[++sta[0]]=x,insta[x]=1;
	vis[x]=1;
	fo(y,1,n)
		if(a[x][y]) dfs(y);
	sta[sta[0]--]=0,insta[x]=0;
}
void dfs1(int x)
{
	vis[x]=1,++cnt[x];
	fo(y,1,n) if(a[x][y] && !vis[y])
	{
		dfs1(y);
	}
}
int main()
{
	//freopen("!.in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d\n",&n);
	fo(i,1,n)
	{
		fo(j,1,n) a[i][j]=getchar()-'0';
		scanf("\n");
		sz[i]=1;
	}
	fo(i,1,n)
	{
		mset(vis,0);
		dfs(i);
	}
	fo(i,1,n)
	{
		mset(vis,0);
		dfs1(i);
	}
	db ans=0;
	fo(i,1,n)
		if(getfa(i)==i) ans+=sz[i]*1.0/cnt[i];
	printf("%.12lf\n",ans);
	return 0;
}

#include <iostream>
#include <stdio.h>

using namespace std;
int ed[101][101];
int visit[101];
void cle()
{
    for(int i = 0; i < 101; i++)visit[i]=0;
}
double cc = 0;
void dfs(int v)
{
    visit[v] = 1;
    cc++;
    for(int i = 1; i < 101; i++)
    {
        if(ed[i][v] == 1 && visit[i] == 0)
        {
            dfs(i);
        }
    }
}
int main()
{
    int n;
    cin >>n;
    for(int i = 1; i <= n; i++)
    {
        string y; cin >> y;
        for(int j = 1; j <= n; j++)
        {
            ed[i][j]= y[j - 1] - '0';
        }
    }
    double u = 0;
    for(int i = 0; i < n; i++)
    {
        cle();
        cc = 0;
        dfs(i+1);
        u+= 1. /cc;
    }
    printf("%.14lf", u);

}
