====== LCA ====== ===== 풀이 ===== * [[ps:lca]] 쿼리를 처리하는 가장 기본적인 형태의 문제. [[ps:problems:boj:11438]]의 쉬운 버전이다. 코드는 그쪽과 동일한 코드를 제출했다. ===== 코드 ===== """Solution code for "BOJ 11437. LCA". - Problem link: https://www.acmicpc.net/problem/11437 - Solution link: http://www.teferi.net/ps/problems/boj/11437 Tags: [LCA] """ import sys from teflib import tree as ttree ROOT = 0 def main(): N = int(sys.stdin.readline()) tree = [[] for _ in range(N)] for _ in range(N - 1): u, v = [int(x) for x in sys.stdin.readline().split()] tree[u - 1].append(v - 1) tree[v - 1].append(u - 1) lca = ttree.LowestCommonAncestor(tree, ROOT) M = int(sys.stdin.readline()) for _ in range(M): u, v = [int(x) for x in sys.stdin.readline().split()] print(lca.lca_node(u - 1, v - 1) + 1) if __name__ == '__main__': main() * Dependency: [[:ps:teflib:tree#LowestCommonAncestor|teflib.tree.LowestCommonAncestor]] {{tag>BOJ ps:problems:boj:골드_3}}