====== Time To Live ====== ===== 풀이 ===== * [[ps:트리의 지름#트리의 중심과 반지름을 구하기|트리의 반지름]] 을 구하는 기본적인 문제. 링크에서 설명하는 알고리즘을 그대로 적용하면 된다. 시간복잡도는 O(n) ===== 코드 ===== """Solution code for "BOJ 3973. Time To Live". - Problem link: https://www.acmicpc.net/problem/3973 - Solution link: http://www.teferi.net/ps/problems/boj/3973 Tags: [tree diameter] """ from teflib import psutils from teflib import tree as ttree @psutils.run_n_times def main(): _, tree = ttree.create_tree_from_input(base=0) print(ttree.DistanceMeasures(tree).radius) if __name__ == '__main__': main() * Dependency: [[:ps:teflib:tree#DistanceMeasures|teflib.tree.DistanceMeasures]] {{tag>BOJ ps:problems:boj:골드_2}}