lundi 18 février 2019

The DFS fails in recursive call

I was trying to solve a problem using DFS, but for large test case DFS doesn't work if I pass the values directly to recursive call but works if I save it in a variable and then pass it in the recursive call, I cannot figure out why it's happening, someone pls help.

    void DFS(int ele, double probability){
      if(out_deg[ele]==0)
        prob[ele] += probability;
      else
      {
        double ppp = probability/adj[ele].size();
        for(auto i: adj[ele])
            DFS(i, ppp);
        /*
        This will not work, for large test cases
        DFS(i, probability/adj[ele].size());
        */
      }
    }

Aucun commentaire:

Enregistrer un commentaire