How to remove cycles from a directed graph by edge contraction? We have cyclic directed graph (possibly disconnected). For cycles consisting of two vertices A->B and B->A, we replace them by a single vertex. In case of A->B, B->C, C->A we also replace them by one vertex. We replace N vertices when all reachable from each other. Edges leaving a vertex stay as edges leaving the group containing the vertex.
For example,

digraph cyclic {
        rankdir=BT;
01
2-&gt;3
3-&gt;2
5-&gt;2
6-&gt;4
8-&gt;3
9-&gt;4
a-&gt;4
a-&gt;9
9-&gt;a
b-&gt;8
b-&gt;c
c-&gt;b
6-&gt;7
7-&gt;8
8-&gt;6
}


We must obtain

digraph acyclic {
        rankdir=BT;
01
5-&gt;23
678-&gt;23
678-&gt;4
a9-&gt;4
bc-&gt;678
}


How is algorithm?
Practical application of problem: we have class where method depends from fields and other methods. How decomposite to max number smallest classes? we allow multiple inheritance, inheritance diamond, but not allow cycles.
Since the only way to get rid of a cycle by edge contractions is to contract all the edges of the cycle to result in a single vertex, the vertices of the new graph are the strongly connected components of the original graph. Two vertices have an edge between them if the original components corresponding to these two vertices had such an edge in the same direction.

Strongly connected components can ve found in linear time.