#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7
#define INF LONG_MAX/3
#define bit(n) (1LL<<(n))

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

string S[105];
vector<ll> ot[105];

set<ll> from[105];

void dfs(ll cur, ll start) {
	if(from[start].count(cur)) return;
	from[start].insert(cur);
	for(ll next: ot[cur]) dfs(next, start);
}

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

	rep(i, N) rep(j, N) {
		if(S[i][j] == '1') {
			ot[j].push_back(i);
		}
	}
	rep(i, N) dfs(i, i);


	double ans = 0;
	rep(i, N) {
		double num = from[i].size();
		ans += 1.0/num;
	}
	printf("%.10f\n", ans);

}
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
inline char rdchar()
{
	char ch=getchar();
	while(!(ch>='a'&&ch<='z')&&!(ch>='A'&&ch<='Z')&&!(ch>='0'&&ch<='9')) ch=getchar();
	return ch;
}
typedef pair<int,int> pii;
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
#define N 105
int a[N][N];
signed main()
{
	int n=read();
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) a[i][j]=rdchar()-'0';
	for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(a[i][k]&&a[k][j]) a[i][j]=1;
	for(int i=1;i<=n;i++) a[i][i]=1;
	double ans=0;
	for(int i=1;i<=n;i++)
	{
		int s=0; for(int j=1;j<=n;j++) s+=a[j][i];
		ans+=(double)n/s;
	}
	printf("%.9lf\n",ans/n);
	return 0;
}


