Reset global state between DFS calls, fix complexity

DFS algorithm uses global (module-scope) variables `time`, `visitedNodes`, `finishingTimes`, and successive calls share their values. This patch fixes it.