DFS corrected for weighted graphs.