The first code is as follows:
The code in question isin the dfs function
This is the double for statement.
위 코드 전체를 제 컴퓨터 VScode에서 mingw의 g++ 컴파일러로 컴파일 한 뒤 실행하면 < img alt = "image" = src cloudinary. // res. : " https com image upload to / / eightcruz v 1651861293 hbnxnaypmwx dtlmpgbz 9.png"/>
As shown above, only plz is output, and the double for statement in the dfs function is not executed.
When I tried debugging, an exception called segmentation fault occurred.
Even if you run it in dev-c++, it only outputs up to plz.
But what's ridiculous is that if you run it on an online idea like repl.it,
The results come out well like in the picture above.
Why do errors only occur on my computer?
And the weird thing is, if you don't call the dfs function and run the double for statement in question, you can move it to the main function and run it well.
If my coding is wrong, I think the same error should occur on repl.it, but I don't know what's wrong with it.
I reset my laptop because of this, but it's the same.
The reason I think is that something went wrong when passing vectorg to the dfs function as a parameter
Compilers on sites like repl.it have translated well on their own for some reason, but my g++ and dev-c++ compilers don't.
What do you think? <c++ segmentation-fault
The code above is invalid.
I think what I originally wanted to do was declare a bowl-type array, visited, but to declare an array, I have to do it in square brackets (
) instead of square brackets (
However, since you cannot declare an array with variables, if you describe it as above, it will be an error, and you must declare an array with a dynamic assignment.
Once you change it like above and run it, the segmentation fault will be resolved.
However, rather than declaring a bowl-type array, it is declared as a vector as above It is more convenient to change the third parameter of the function as shown below.
© 2022 pinfo. All rights reserved.