Strongly connected component help

why this code C++ CODE is giving WA,
for this problem C-Connect Cities
it would be really nice if somebody could help?
it is passing for samples [mine ]

The Roads are bidirectional that means if there is a path from a->b then b->a is a path too. You are only adding one path you aren’t adding the other path.

    else
    {
        tre[a].push_back(b);
    }

Also when you are going into DFS you are not marking the city as visited, You are directly checking it’s child node without marking the parent visited.

2 Likes