ps:problems:boj:12896
                스크루지 민호
| ps | |
|---|---|
| 링크 | acmicpc.net/… | 
| 출처 | BOJ | 
| 문제 번호 | 12896 | 
| 문제명 | 스크루지 민호 | 
| 레벨 | 골드 2 | 
| 분류 | 
 트리의 지름  | 
	
| 시간복잡도 | O(n) | 
| 인풋사이즈 | n<=100,000 | 
| 사용한 언어 | Python 3.13 | 
| 제출기록 | 56252KB / 312ms | 
| 최고기록 | 216ms | 
| 해결날짜 | 2025/10/31 | 
풀이
- 트리의 반지름 을 구하는 기본적인 문제. 링크에서 설명하는 알고리즘을 그대로 적용하면 된다. 시간복잡도는 O(n)
 
코드
"""Solution code for "BOJ 12896. 스크루지 민호".
- Problem link: https://www.acmicpc.net/problem/12896
- Solution link: http://www.teferi.net/ps/problems/boj/12896
Tags: [tree diameter]
"""
from teflib import tree as ttree
def main():
    _, tree = ttree.create_tree_from_input()
    print(ttree.DistanceMeasures(tree).radius)
if __name__ == '__main__':
    main()
- Dependency: teflib.tree.DistanceMeasures
 
ps/problems/boj/12896.txt · 마지막으로 수정됨: 2025/10/31 06:45 저자 teferi
                
                
토론