728x90 최소공통조상1 [python] 백준 11438 LCA 2 https://www.acmicpc.net/problem/11438 문제 해결최소 공통 조상을 찾는 알고리즘을 LCA (Lowest common ancestor)이라 한다.트리 구조에서 level을 가지고 층의 차이를 좁힌 다음 하나씩 동시에 level을 올려 parent를 확인한 다음 동시에 같은 parent가 될 때 까지 학인하는 알고리즘 코드이다. CODE import sysinput = sys.stdin.readlinemax_depth = 10000log = 21n = int(input())graph = [[] for _ in range(n+1)]for _ in range(n-1): a, b = map(int, input().split()) graph[a].append(b) gra.. 2024. 6. 6. 이전 1 다음 728x90