the only noticeable difference I can see is he is using global variables and I am using local ones so does it make any difference as I already know in the precomputation case it does but in this code we are not precomputing still I get TLE what is the catch here please explain someone Thanks in advance.
using namespace std;
const unsigned int M = 1000000007;
void graphDFScomponentcounter(int node,vector<vector<int>> v, vector<bool> &vmarked,int &counter ){ // The bug is here
vmarked[node]=true;
counter++;
fri(i,0,v[node].size()){
if (!vmarked[v[node][i]]){
graphDFScomponentcounter(v[node][i],v,vmarked,counter);
}
}
}
The reason behind TLE is the method signature.
It should have been void graphDFScomponentcounter(int node,vector<vector<int>> &v, vector<bool>&vmarked,int &counter )
Instead