Here is a randomized algorithm to estimate the number of vertices within distance d of each vertex in a directed graph with n vertices and m edges in fully polynomial time:
1. Repeat the following r times for a sufficiently large value of r:
2. Color each vertex randomly with probability 1/2d.
3. For each vertex v, count the number of colored vertices within distance d of v. Let this count be cv.
4. Return, for each vertex v, the estimate cvr/n as the number of vertices within distance d of v.
This algorithm runs in O(rm) time, which is fully polynomial for any fixed d, as r can be taken to be a polynomial in