title: BFS "Digit Jump" solution working fine on machine, get TLE on online judge
body: <p>This code is for problem <a href="https://www.codechef.com/problems/DIGJUMP" rel="nofollow">DIGJUMP</a>.</p>
  
  <p>It gives me correct output for all inputs i have tried (i have tried a lot of them). But the problem is that it is getting TLE while submitting it on codechef. I checked the editorial and the same solution (concept-wise) gets accepted, so it means algorithmic approach is correct. I must have something wrong in the implementation.</p>
  
  <p>I tried it for a long time, but could not figure out what is wrong.</p>
  
  <pre><code>#include &lt;string.h&gt;
  #include &lt;vector&gt;
  #include &lt;queue&gt;
  #include &lt;stdio.h&gt;
  
  using namespace std;
  
  class Node
  {
      public:
      int idx, steps;
  };
  
  int main()
  {
      char str[100001];
      scanf("%s", str);
      int len = strlen(str);
  
      vector&lt;int&gt; adj[10];
      for(int i = 0; i &lt; len; i++)
          adj[str[i] - '0'].push_back(i);
  
      int idx, chi, size, steps;
      Node tmpn;
      tmpn.idx = 0;
      tmpn.steps = 0;
  
      queue&lt;Node&gt; que;
      que.push(tmpn);
  
      bool * visited = new bool[len];
      for(int i = 0; i &lt; len; i++)
          visited[i] = false;
  
      while(!que.empty())
      {
          tmpn = que.front();
          que.pop();
          idx = tmpn.idx;
          steps = tmpn.steps;
          chi = str[idx] - '0';
  
          if(visited[idx])
              continue;
          visited[idx] = true;
  
          if(idx == len - 1)
          {
              printf("%d\n", tmpn.steps);
              return 0;
          }
  
          if(visited[idx + 1] == false)
          {
              tmpn.idx = idx + 1;
              tmpn.steps = steps + 1;
              que.push(tmpn);
          }
  
          if(idx &gt; 0 &amp;&amp; visited[idx - 1] == false)
          {
              tmpn.idx = idx - 1;
              tmpn.steps = steps + 1;
              que.push(tmpn);
          }
  
          size = adj[chi].size();
          for(int j = 0; j &lt; size; j++)
          {
              if(visited[adj[chi][j]] == false)
              {
                  tmpn.idx = adj[chi][j];
                  tmpn.steps = steps + 1;
                  que.push(tmpn);
              }
          }
      }
      return 0;
  }
  </code></pre>