Graph complexity


for a graph that has N nodes (with N<=10^4) is an O(n^2) complexity acceptable or it is possible to have a lower complexity?
Depth First Search is in O(n log(n)) but when I apply it for N nodes the total complexity becomes O(n^2 log(n)).
What should I do to better optimize my code?
Thank you :slight_smile:

DFS is O(V+E) and not O(VlogV)

O(n^2)complexity for N<=10^4 will not pass a time limit of 1s.try a different approach.

Okay but when I apply it for V nodes it will be O(V^2) right?