I am new to cpp, and tried to solve a dfs problem, please look into it and tell me what’s causing this.
Please don’t suggest me a better way of writing code/ small code for this problem as I’m trying on my own to solve the problem using the standard algorithm. Thanks
First you have created a vector named as profit of length 1 and then you are inserting elements into the vector from 1 to n . This is one of the problems i can see for now. Change it and then tell what’s the output.
Also, you can create graph like this :-
Dont use map it makes your program slow…
In the dfs function, you have initialised the value of start and p =1 so whenever dfs will get called no matter what the value of start and p is, it will eventually become 1 at the starting of the function.
SIGABRT error is solved. Now its just WA’s and TLE’s.
Wrong answer is because you have visited.empty(), instead you have to use visited.clear().
TLE is there because you are using map to represent graph. Use 2D vector to represent graph.
Then your answer will be accepted.
thanks but I solved it already