# Chef and Digit Jumps : getting WA

i am getting wrong answer but passing the sample cases;
problem : `[chef and digit jumps](https://www.codechef.com/LRNDSA08/problems/DIGJUMP)`

``````#include <bits/stdc++.h>
using namespace std;
class Graph
{ public:
map<int,list<int>> l;
{
l[x].push_back(y);
}
void print()
{
for(auto node_pair : l)
{
cout<<node_pair.first<<"->";
for(auto ngh: l[node_pair.first])
{cout<<ngh<<" , ";}
cout<<endl;
}
}
int bfs (int src,int dest)
{// cout<<"s"<<src<<" "<<"d"<<dest<<endl;
map<int,int> dist;
queue<int> q;

for( auto node_pair : l)
{ int node = node_pair.first;
dist[node]=INT_MAX;
}
dist[src]=0;
q.push(src);
while(!q.empty())
{
int n = q.front();
q.pop();
for(int ngh : l[n])
{
if(dist[ngh]==INT_MAX)
{q.push(ngh);
dist[ngh]=dist[n]+1;}
}
}
/* for(auto node_pair: l)
{
int node= node_pair.first;
cout<<node<<" "<<dist[node]<<endl;
} */
return dist[dest];
}

};

int main() {
string str;
cin>>str;
Graph g;

int i;
vector<int> s;
for(i=0;i<str.length();i++)
{
int x= str[i]-'0';
s.push_back(x);
}

for( i =0;i<s.size();i++)
{
if(i>0)
{  if(g.l.find(s[i])!=g.l.end())
{ auto it =g.l.find(s[i]);
s[i]= s[i]+10;

}
// g.print();
// cout<<"x "<< x<<endl;
int x = s.size();
int ans= g.bfs(s[0],s[x-1]);
cout<<ans<<endl;
return 0;
}
``````

I donâ€™t understand how your graph template works and your logic seems wrong, can you explain it?

I have formed a directed graph. connecting the digits which we can reach from a particular digit. thus i have added an edge from s[i-1] to s[i]. if a no is repeating in the sequence that is that node is already present in the graph, i am changing its value and connecting it to the previous valued node present in the graph.
after forming the graph i am finding the shortest path frm src to destination using bfs.

For the string `000` are you taking into account that you can jump to the last `0` from the first one?

yes the second zero is connected to first zero and then its value is changed to 10 - 0 = 0, the third zero is also connected to first zero

what other approach can be used to connect them?