it is SIGILL (Illegal instruction), when I was solving the problem 797 on leetcode:Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n – 1, find all possible paths from node 0 to node n – 1 and return them in any order.
The graph is given as follows: graph[i] is a list of all nodes you can visit from node i (i.e., there is a directed edge from node i to node graph[i][j]).
I write the code like that:
bool DFS(vector<vector<int>>& graph,vector<vector<int>>&ans,vector<int>&path,int Node){
if(Node==graph.size()-1){
path.push_back(Node);
ans.push_back(path);
path.pop_back();
return true;
}
for(auto posNode:graph[Node]){
path.push_back(Node);
if(!DFS(graph,ans,path,posNode)){
path={-1};
return false;
}
}
}
vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
int Node=0;
vector<vector<int>>ans;
for(auto posNode:graph[Node]){
vector<int>path;
path.push_back(Node);
if(DFS(graph,ans,path,posNode)){
ans.push_back(path);
}
}
return ans;
}
when the program goes to:for(auto posNode:graph[Node]) in DFS, it throws out a exception which is: SIGILL (Illegal instruction). why this accrued?
Zhihan Jiang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.