#AGC049A. [AGC049A] Erasing Vertices

[AGC049A] Erasing Vertices

Score : 400400 points

Problem Statement

We have a directed graph with NN vertices numbered 11 to NN. NN strings of length NN each, S1,S2,,SNS_1,S_2,\ldots,S_N, represent the edges in the graph. Specifically, Si,jS_{i,j} is 1 if there is an edge from Vertex ii to Vertex jj, and 0 otherwise. The graph has no self-loops and no multi-edges.

Until the graph becomes empty, AtCobear will repeat the following operation:

  • Choose one (unerased) vertex uniformly at random (independently from the previous choices). Then, erase that vertex and all vertices that are reachable from the chosen vertex by traversing some edges. Erasing a vertex will also erase the edges incident to it.

Find the expected value of the number of times the operation is done.

Constraints

  • 1N1001 \leq N \leq 100
  • SiS_i is a string of length NN consisting of 0 and 1.
  • Si,i=S_{i,i}=0

Input

Input is given from Standard Input in the following format:

NN

S1S_1

S2S_2

\vdots

SNS_N

Output

Print the expected value of the number of times the operation is done. Your output will be considered correct when its absolute or relative error from our answer is at most 10910^{-9}.

3
010
001
010
1.66666666666666666667

We have the following three scenarios happening with equal probability:

  • Choose Vertex 11 in the first operation, erasing Vertex 11, 22, and 33. The graph is now empty, so we are done.
  • Choose Vertex 22 in the first operation, erasing Vertex 22 and 33. Then, choose Vertex 11 in the second operation, erasing Vertex 11. The graph is now empty, so we are done.
  • Choose Vertex 33 in the first operation, erasing Vertex 22 and 33. Then, choose Vertex 11 in the second operation, erasing Vertex 11. The graph is now empty, so we are done.

Thus, the expected value of the number of times the operation is done is (1+2+2)/3=5/3(1+2+2)/3=5/3.

3
000
000
000
3.00000000000000000000

There will always be three operations.

3
011
101
110
1.00000000000000000000

There will always be one operation.