title: How i make bfs more efficient in cpp
body: <p>I have problem in unweighted undirected graph the question ask if any path between two point in binary matrix, the user insert the matrix and the cell in matrix to test</p>
  <pre><code>bool BFS(vector&lt;vector&lt;int&gt;&gt;mat, Point src, Point dest,int n,int m)
  {
      
      if (!mat[src.x][src.y] || !mat[dest.x][dest.y])
          return 0;
      
      bool visited[n][m];
      memset(visited, false, sizeof visited);
      
      
      visited[src.x][src.y] = true;
      
      
      queue&lt;queueNode&gt; q;
      
      queueNode s = {src};
      q.push(s);
      
      while (!q.empty())
      {
          queueNode curr = q.front();
          Point pt = curr.pt;
          
          
          if (pt.x == dest.x &amp;&amp; pt.y == dest.y)
              return 1;
          
          
          q.pop();
          
          for (int i = 0; i &lt; 8; i++)
          {
              int row = pt.x + rowNum[i];
              int col = pt.y + colNum[i];
              
              if (isValid(row, col,n,m) &amp;&amp; mat[row][col] &amp;&amp;
                  !visited[row][col])
              {
                  
                  visited[row][col] = true;
                  queueNode Adjcell =  {row, col};
                  q.push(Adjcell);
              }
          }
      }
      
      
      return 0;
  }
  </code></pre>
  <p>In hacker rank some test not work properly because timeout.
  Any one can help please?</p>