We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
💬 문제
https://www.acmicpc.net/problem/3584
💬 Idea
💬 풀이
import Foundation func solution3584() { let t = Int(readLine()!)! for _ in 1...t { let n = Int(readLine()!)! var nodes = Array(repeating: 0, count: n + 1) for _ in 1..<n { let node = readLine()!.components(separatedBy: .whitespaces).map({ Int($0)! }) nodes[node[1]] = node[0] } func dfs(_ start: Int) -> [Int] { var visitedQueue: [Int] = [] var needToVisitNode = start while needToVisitNode != 0 { visitedQueue.append(needToVisitNode) needToVisitNode = nodes[needToVisitNode] } return visitedQueue } let tc = readLine()!.components(separatedBy: .whitespaces).map({ Int($0)! }) func getCommonAncestor(_ n1: Int, _ n2: Int) -> Int { let queue1 = dfs(n1) let queue2 = dfs(n2) return queue1.filter({ queue2.contains($0) }).first! } print(getCommonAncestor(tc[0], tc[1])) } }
The text was updated successfully, but these errors were encountered:
#215 - 가장 가까운 공통 조상 문제 풀이
5f34f50
hwangJi-dev
No branches or pull requests
💬 문제
https://www.acmicpc.net/problem/3584
💬 Idea
💬 풀이
The text was updated successfully, but these errors were encountered: