I write some codes about finding strongly connected components.
using edge=pair<int, int>;
void dfsSCCFind(int vertex, vector<vector <int>>& adj, vector<int>& check, vector<int>& SCC, vector<edge>& SCCEdge){
if(check[vertex]==0){
check[vertex]=1;
SCC.push_back(vertex);
for(int i=0; i<(int)adj[vertex].size();i++){
int neighbor=adj[vertex][i];
if(check[neighbor]==0){
SCCEdge.push_back({vertex, neighbor});
dfsSCCFind(neighbor, adj, check, SCC, SCCEdge);
}
}
}
}
My main function call 'dfsSCCFind'for all vertices in a graph.
But it makes unknown signal 11. I think it might be due to stackoverflow.
So, I added the code enlarge the stack size and it works properly.
However when I modify the code like below, it works properly without enlarging stack size.
void dfsSCCFind(int vertex, vector<vector <int>>& adj, vector<int>& check, vector<int>& SCC){
if(check[vertex]==0){
check[vertex]=1;
SCC.push_back(vertex);
for(int i=0; i<(int)adj[vertex].size();i++){
int neighbor=adj[vertex][i];
if(check[neighbor]==0){
dfsSCCFind(neighbor, adj, check, SCC, SCCEdge);
}
}
}
}
I just deleted a vector parameter and the code related with it.
I know vector is allocated on heap, not stack. Therefore, I think it is not related with "Unknown signal 11"
if it is related with the maximum heap size, it might not have been solved by enlarging stack size.
What is the cause of my code?