RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00078

Krtica

스페셜 저지 — 출력을 사용자 정의 프로그램으로 검사하므로 여러 정답이 인정될 수 있습니다.
Diamond V 다이아몬드 V
난이도
3s
시간 제한
128MB
메모리 제한
1
맞았습니다!!
1
제출 수
100.0%
정답률
레이팅

의견: 0

설명

Moles are tidy and ha\(rd-wo\)rking animals. Our mole likes to keep its underground residence in utmost
order, so that everyone living there knows where to find things.
To achieve this, the mole connected rooms with tunnels so that there is a single unique way to get from
one room to any other room. The distance between two rooms is the number of halls passed on the
way from one to the other.
Despite all the effort, some of the mole's guests are complaining that it takes too long to walk between
certain pairs of rooms.
The mole decided to reconstruct her residence, closing one tunnel and opening a new one, so that the
distance between the farthest two rooms is the smallest possible, but so that it is still possible to
reach every room from every other room.
Write a program which determines the distance between the farthest two rooms after reconstruction,
which tunnel to close and which to open.

제약
입력 형식

The first line contains an integer \(N\) (\(1 \le N \le 300\,000\)), the number of rooms. The rooms are numbered \(1\) to \(N\).

Each of the next \(N-1\) lines contains two integers, the numbers of rooms a tunnel connects.

출력 형식

Output on separate lines, in order:

  • The distance between the two farthest rooms after reconstruction.
  • A pair of integers representing a previously existing tunnel, which should be closed.
  • A pair of integers, the rooms between which a new tunnel should be opened.

Note: The solution will not necessarily be unique. Output any reconstruction plan which achieves the smallest distance between the farthest two rooms.

Scoring: In test cases worth \(40\%\) of points, \(N\) will be less than \(30\). In test cases worth \(70\%\) of points, \(N\) will be less than \(3000\). Additionally, if the first line of your output is correct and the other two are missing or incorrect, you will receive about \(70\%\) of the value of that test case.

서브태스크
서브태스크점수설명

Subtask 1

56점

\(N < 30\)

Subtask 2

42점

\(N < 3000\)

Subtask 3

42점

No additional constraints (\(N \le 300\,000\)).

예제 1
입력
4
1 2
2 3
3 4
출력
2
3 4
4 2
예제 2
입력
7
1 3
2 3
2 7
4 3
7 5
3 6
출력
3
2 3
7 3
문제 정보

riseoj 작성

출처 COCI 2008/2009 Contest 1

평가 및 의견

Krtica

개요
출제자 난이도 Diamond V 다이아몬드 V 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Krtica

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8