func dfs(_ start: Int) -> [Int] {
var visitedQueue = [Int]()
var needVisitedQueue = [start]
while !needVisitedQueue.isEmpty {
let node: Int = needVisitedQueue.removeLast()
if visitedQueue.contains(node) { continue }
visitedQueue.append(node)
needVisitedQueue += graph[node].reversed()
}
return visitedQueue
}
func bfs(_ start: Int) -> [Int] {
var visitedQueue = [Int]()
var needVisitedQueue = [start]
while !needVisitedQueue.isEmpty {
let node: Int = needVisitedQueue.removeFirst()
if visitedQueue.contains(node) { continue }
visitedQueue.append(node)
needVisitedQueue += graph[node]
}
return visitedQueue
}