The error says segmentation fault but I can’t spot it
I can't spot the error
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, start;
cin>>n>>start;
vector v;
for(int i=0;i<n;i++){
cin>>v[i];
}
// zeroes vector
vector zeroes;
for(int i=0;i<v.size();i++){
if(v[i]==0)
zeroes.push_back(i);
}
map<int,list> m;
for(int i=0;i<v.size();i++){
if(v[i]==0){
continue;
}
else{
if(i+v[i]<n){
m[i].push_back(i+v[i]);
}
if(i-v[i]>=0){
m[i].push_back(i-v[i]);
}
}
}
vector visited(n,false);
queue q;
q.push(start);
visited[start]=true;
while(!q.empty()){
int temp= q.front();
q.pop();
for(int child: m[temp]){
if(!visited[child]){
q.push(child);
visited[child]=true;
}
}
}
int k=0;
for(int i=0;i<zeroes.size();i++){
if(visited[zeroes[i]]){
cout<<“YES”;
k=1;
break;
}
}
if(k==0){
cout<<“NO”;
}
return 0;
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.