atcoder#AGC049A. [AGC049A] Erasing Vertices
[AGC049A] Erasing Vertices
Score : points
Problem Statement
We have a directed graph with vertices numbered to .
strings of length each, , represent the edges in the graph.
Specifically, is 1
if there is an edge from Vertex to Vertex , 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
- is a string of length consisting of
0
and1
. 0
Input
Input is given from Standard Input in the following format:
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 .
3
010
001
010
1.66666666666666666667
We have the following three scenarios happening with equal probability:
- Choose Vertex in the first operation, erasing Vertex , , and . The graph is now empty, so we are done.
- Choose Vertex in the first operation, erasing Vertex and . Then, choose Vertex in the second operation, erasing Vertex . The graph is now empty, so we are done.
- Choose Vertex in the first operation, erasing Vertex and . Then, choose Vertex in the second operation, erasing Vertex . The graph is now empty, so we are done.
Thus, the expected value of the number of times the operation is done is .
3
000
000
000
3.00000000000000000000
There will always be three operations.
3
011
101
110
1.00000000000000000000
There will always be one operation.