i dont know why am getting one WA
i cant identify my mistake
please help
my code:
https://ide.codingblocks.com/s/75897
question link:
https://hack.codingblocks.com/contests/c/668/766
i dont know why am getting one WA
i cant identify my mistake
please help
my code:
https://ide.codingblocks.com/s/75897
question link:
https://hack.codingblocks.com/contests/c/668/766
please reply maam / sir
@sanjeetboora
@tusharsk
atleast give me a test case for which my code gives wrong output;
Hey, your code isnt there, please put a link to your code
#include<bits/stdc++.h>
using namespace std;
class graph{
public:
unordered_map<int,list>adjlist;
void insert(int u,int v){
adjlist[u].push_back(v);
}
void bfs(int src){ /// graph
queue<int>q;
unordered_map<int,int>dist;
map<int,bool>visited;
q.push(src);
bool f=0;
while(!q.empty()){
int parent =q.front();
q.pop();
for(auto i:adjlist[parent]){
if(!visited[i]){
visited[i]=1;
q.push(i);
dist[i]=dist[parent]+1;
if(i==100){
f=1;
break;
}
}
}
if(f){
break;
}
}
cout<<dist[100]<<endl;
}
};
int main() {
int t;
cin>>t;
while(t–){
int n;
cin>>n;
graph g;
int l[101]={0}; // for ladder
for(int i=0;i<n;i++){
int x,y;
cin>>x>>y;
l[x]=y-x; ////// change =final position minus initial position
}
cin>>n;
int s[101]={0}; // for snake
for(int i=0;i<n;i++){
int x,y;
cin>>x>>y;
s[x]=y-x; /// change =final position minus initial position
}
for(int i=0;i<=99;i++){
for(int j=i+1;j<=100 && j-i<=6;j++){
g.insert(i,j+l[j]+s[j]); // making the graph
}
}
g.bfs(1);
}
}