Erasing Vertices

AtCoder
IDagc049_a
Time2000ms
Memory256MB
Difficulty
We have a directed graph with $N$ vertices numbered $1$ to $N$. $N$ strings of length $N$ each, $S_1,S_2,\ldots,S_N$, represent the edges in the graph. Specifically, $S_{i,j}$ is `1` if there is an edge from Vertex $i$ to Vertex $j$, 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 * $1 \leq N \leq 100$ * $S_i$ is a string of length $N$ consisting of `0` and `1`. * $S_{i,i}=$`0` ## Input Input is given from Standard Input in the following format: $N$ $S_1$ $S_2$ $\vdots$ $S_N$ [samples]
Samples
Input #1
3
010
001
010
Output #1
1.66666666666666666667

We have the following three scenarios happening with equal probability:

*   Choose Vertex $1$ in the first operation, erasing Vertex $1$, $2$, and $3$. The graph is now empty, so we are done.
    
*   Choose Vertex $2$ in the first operation, erasing Vertex $2$ and $3$. Then, choose Vertex $1$ in the second operation, erasing Vertex $1$. The graph is now empty, so we are done.
    
*   Choose Vertex $3$ in the first operation, erasing Vertex $2$ and $3$. Then, choose Vertex $1$ in the second operation, erasing Vertex $1$. 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$.
Input #2
3
000
000
000
Output #2
3.00000000000000000000

There will always be three operations.
Input #3
3
011
101
110
Output #3
1.00000000000000000000

There will always be one operation.
API Response (JSON)
{
  "problem": {
    "name": "Erasing Vertices",
    "description": {
      "content": "We have a directed graph with $N$ vertices numbered $1$ to $N$. $N$ strings of length $N$ each, $S_1,S_2,\\ldots,S_N$, represent the edges in the graph. Specifically, $S_{i,j}$ is `1` if there is an ed",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "agc049_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We have a directed graph with $N$ vertices numbered $1$ to $N$. $N$ strings of length $N$ each, $S_1,S_2,\\ldots,S_N$, represent the edges in the graph. Specifically, $S_{i,j}$ is `1` if there is an ed...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments