#include <bits/stdc++.h> 
using namespace std;
int n;
double ans;
bool can[105][105];

int main() {
	cin>>n;
	for (int i=1; i<=n; ++i)
		for (int j=1; j<=n; ++j) {
			char c; cin>>c;
			can[i][j]=c=='1';
		}
	for (int i=1; i<=n; ++i)
		can[i][i]=1;
	for (int k=1; k<=n; ++k)
		for (int i=1; i<=n; ++i)
			for (int j=1; j<=n; ++j)
				can[i][j]|=can[i][k]&&can[k][j];
	for (int i=1; i<=n; ++i) {
		int now=0;
		for (int j=1; j<=n; ++j)
			now+=can[j][i];
		ans+=1.0/now;
	}
	printf("%.13lf",ans);
}
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef map<ll, ll> ml;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {return (a % b + b) % b;}
ll quo(ll a, ll b) {return (a - mod(a, b)) / b;}
template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;}
template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 2e5;
const ld eps = 1e-9;
const char newl = '\n';

ll itr1, itr2, M1 = 0, M2 = 0;
bool found = 0;
vl e, d1, d2;
vb diam;
vvl G;

void dfs1(ll v) {
  for(ll u: G[v]) {
    if(d1[u] == INF) {
      d1[u] = d1[v] + 1;
      dfs1(u);
    }
  }
  return;
}

void dfs2(ll v) {
  for(ll u: G[v]) {
    if(d2[u] == INF) {
      d2[u] = d2[v] + 1;
      dfs2(u);
    }
  }
  return;
}

void dfs3(ll v) {
  if(v == itr2) {
    found = 1;
    return;
  }
  for(ll u: G[v]) {
    if(found) break;
    if(d2[v] < d2[u]) dfs3(u);
    if(found) diam[u] = 1;
  }
  return;
}

ll dfs4(ll v, ll num) {
  e[v] = num;
  ll last = -1;
  for(ll u: G[v]) {
    if(e[u] == INF) {
      if(diam[u]) {
        last = u;
        continue;
      }
      num = dfs4(u, num+1);
    }
  }
  if(last != -1) num = dfs4(last, num+1);
  return num+1;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n, a, b;
  cin >> n;
  e = vl(n, INF);
  d1 = vl(n, INF);
  d2 = vl(n, INF);
  diam = vb(n, 0);
  G = vvl(n);
  rep(_, n-1) {
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  d1[0] = 0;
  dfs1(0);
  rep(i, n) if(chmax(M1, d1[i])) itr1 = i;
  d2[itr1] = 0;
  dfs2(itr1);
  rep(i, n) if(chmax(M2, d2[i])) itr2 = i;
  dfs3(itr1);
  dfs4(itr1, 1);
  //cout << itr1 << " " << itr2 << newl;
  //rep(i, n) if(diam[i]) cout <<i << newl;
  rep(i, n) cout << e[i] << ' ';
  cout << newl;
  return 0;
} 