목차

구름다리

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()