Infiltration

시간 제한1초메모리 제한1024 MB

요약
방 100개짜리 트리에서 두 요원이 홀수 분과 짝수 분에 번갈아 이동하거나 머무는 전략을 세워 최대한 빨리 만나야 한다. 시작 거리로 나눈 만남 시간의 최댓값을 최소화하는 전략을 출력한다.
난이도

어려움10점 중 9점

유형
트리, 그리디, 게임 이론, 구현
정답자
아직 제출이 없습니다

문제

Ondrej and Edward are spies and they are going to take down the evil organization AQT. To do so, they will need to infiltrate into the AQT base. The base can be modelled as a tree with N=100N = 100 rooms, labelled from 00 to N−1N - 1. Ondrej and Edward’s plan to infiltrate the base is to first get kidnapped and then meet up together before executing their plan. When kidnapped, the two will be placed into different rooms unknown to each other. Once they are placed into the rooms, they will both break free at midnight and try to meet up with each other before executing their plan.

Their plan to meet up is as follows. At every odd minute, Ondrej can choose to stay at his current room or move to an adjacent room. At every even minute, Edward can choose to stay at his current room or move to an adjacent room.

A strategy is defined as the following. Let V(A,R,T)V(A, R, T) denote the room agent AA should be at assuming that they were at room RR at midnight and it is currently TT minutes after midnight. The strategy should match the conditions above. The agents are said to meet up at time t(o,e)t(o, e), which is the first time where V(Ondrej,o,t(o,e))=V(Edward,e,t(o,e))V(\text{Ondrej}, o, t(o, e)) = V(\text{Edward}, e, t(o, e)).

Ondrej and Edward want to meet up as fast as possible, relative to the distance between their two starting rooms. The distance d(o,e)d(o, e) is the minimum number of corridors that must be traversed to reach oo from ee. Please help find a strategy that minimizes the maximum t(o,e)d(o,e)\frac{t(o,e)}{d(o,e)} across all pairs of different rooms oo and ee.

입력

The first line of input will contain NN (N=100N = 100). If the value of NN is anything other than 100100, exit the program immediately.

The next N−1N - 1 lines will each contain two space-separated integers, denoting the labels of two rooms with a bidirectional corridor between them.

출력

First output a positive number TT, the number of entries per starting room. Note that T≤1440T ≤ 1440 must be satisfied, otherwise you will be awarded no points.

Then, output Ondrej’s strategy, followed by Edward’s strategy.

To output an agent’s strategy, output NN lines, where the nn-th line (starting from 00) represents the agent’s path if they start at room nn. For each line, output TT spaced integers: The room label that the agent should be in at time 1,2,…,T1, 2, \dots , T.

예제1

  1. 예제 1

    입력
    5
    0 2
    3 2
    1 4
    2 4
    
    예상 출력
    8
    2 2 4 4 1 1 1 1
    1 1 1 1 1 1 1 1
    3 3 2 2 3 3 2 2
    3 3 2 2 0 0 2 2
    4 4 4 4 2 2 2 2
    0 2 2 3 3 3 3 2
    1 4 4 2 2 0 0 0
    2 3 3 3 3 3 3 3
    3 3 3 3 3 3 3 3
    4 1 1 1 1 4 4 4