Algorithm to check if G contains arborescence

Prediction of a directed graph G is a rooted tree, so there is a directed path from the root to any other vertex of the graph. Give an efficient and correct algorithm to check if G arborescence contains and its time complexity.

I could only think of starting DFS / BFS from each node until all nodes were closed in one of the DFS. I was thinking about using the min spanning tree algorithm, but this also only applies to undirected graphs

is there any other efficient algorithm for this?

I found the following question that claims there is an O (n + m) algorithm for it, can anyone help in solving the problem?

+4
source share
3

, , - . , . MST arborescence, , - , .

- O (EV), Prim MST, , .

:

+6

, , , , , . Wikipedia: , , , G . , .

: - . , DFS G, , , . , ?

  • DFS "" , . , , . , , , , , , root.

  • , , . - , . - .

- O ( + ), , .

+1

, , . - . , DFS node BFS , - , , . BFS, node, , , , , node, node node, , node .

DFS, .

edgeCb()
{
    // Already processed and has no parent means this must a sub tree
    if ( g->par[ y ] == -1 && g->prc[ y ] )
        g->par[ y ] = x; // Connecting two disconnected BFS/DFS trees
    return 1;
}

graphTraverseDfs( g, i )
{
    // Parent of each vertex is being updated as and when it is visited.
}

main() {
.
.
for ( i = 0; i < g->nv; i++ )
    if ( !g->vis[ i ] )
        graphTraverseDfs( g, i );
.
.
}
0

All Articles