What's wrong in my code

mistake 1:
if(parent[i] == -1)
{
count[i] = 1;
continue;
}
add this condition in
int totalWays() {
unordered_map<int, int> count;

    for (int i = 0; i < V; ++i)
    {
        if(parent[i] == -1)
        {
            count[i] = 1;
            continue;
        }
        count[parent[i]]?count[parent[i]]++: count[parent[i]]=1;
    }

for singular nodes

now this would solve half of your problem
for wrong answers
u will get 3 test cases as runtime error
i think you should try fixing that on your own once,
u can also try alternate approaches
like dfs
of floyd warshall algo