ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 22967 |
문제명 | 구름다리 |
레벨 | 골드 2 |
분류 |
애드혹 |
시간복잡도 | O(n) |
인풋사이즈 | n<=300 |
사용한 언어 | Python 3.13 |
제출기록 | 32412KB / 40ms |
최고기록 | 36ms |
해결날짜 | 2025/04/03 |
"""Solution code for "BOJ 22967. 구름다리".
- Problem link: https://www.acmicpc.net/problem/22967
- Solution link: http://www.teferi.net/ps/problems/boj/22967
Tags: [ad hoc]
"""
import itertools
import sys
from teflib import tree as ttree
def main():
N = int(sys.stdin.readline()) # pylint: disable=unused-variable
tree = ttree.create_tree_from_input(N)
if N == 2:
print('0')
print('1')
elif N <= 4:
answers = [
(u, v)
for u, v in itertools.combinations(range(N), 2)
if v not in tree[u]
]
print(len(answers))
print('1')
for u, v in answers:
print(u + 1, v + 1)
else:
adjs = set(range(1, N)) - set(tree[0])
print(len(adjs))
print('2')
for v in adjs:
print(1, v + 1)
if __name__ == '__main__':
main()