Hello I am trying to solve simple graph algorithms problem counting room. In this problem I am getting runtime and time limit exceeded if vector is not defined globally. Can someone tell why this is happening.
Problem link – Counting rooms
Accepted code – Accepted code
TLE and RE showing code – Rejected code
My approach- I am calling dfs function for every unvisited cell and coloring the visited cell.
The number of times dfs is called will be the answer.
>Solution :
In the Rejected code you are passing vector by value which is making copies of the the vector again and again.