Religious people problem


its showing segmentation fault please correct my mistake

@manmeetkahlon
Line 40.

vector<int> visited(V);

@tarunluthra there’s run time error now. Can you suggest any optimized approach?

@manmeetkahlon

  1. Put this at the beginning of dfs helper function
if(visited[src]){
     return;
}
  1. Also you are deciding your verdict in some testcases before even taking the entire input.
    The if condition if(b>=a) is checked before even you take the input for cities. Even though it can give you your answer if it executes, what it does is it messes up your further testcases. Your next testcase would take input from that point only , that is the cities input that you left for previous testcase will now be considered the start of your next testcase and those values will be read as n,m,a,b and so on.
    Take the full input first and then do the evaluations. Not before.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.