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

Papricice

Unrated 레이팅 미적용
난이도
1s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Afrika paprika! – S.V.
After a tiring morning in the garden, Mr. Malnar decided to reward himself with dried hot peppers he
grew himself.
He has \(n\) peppers, connected with \(n - 1\) pieces of string, so that every two peppers are connected by some
series of strings. Formally, they form a tree.
Mr. Malnar will partake in three lunches today. For that purpose, he will cut two strings to get three
smaller components, one for each lunch.
1
2
3
4
5
6
7
8
9
The tree from the third example along with the optimal cuts.
It’s bad to make any lunch too spicy, so he will choose the cuts in a way that minimises the difference
between the size of the largest and the smallest component. You need to determine the sought
minimum difference.

제약

Subtask 1 (15 points): \(3 \le n \le 200\)

Subtask 2 (35 points): \(3 \le n \le 2000\)

Subtask 3 (60 points): \(3 \le n \le 200\,000\)

입력 형식

The first line contains an integer \(n\), the number of peppers. The peppers are labeled by integers from 1 to
\(n\).
Each of the following \(n - 1\) lines contains two integers \(x\) and \(y\) (\(1 \le x\), \(y \le n\)) – labels of peppers that are
directly connected by a piece of string.

출력 형식

Print the minimum possible difference of component sizes.

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

1

15점

\(3 \le n \le 200\)

2

35점

\(3 \le n \le 2000\)

3

60점

\(3 \le n \le 200\,000\)

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

생성자가 기록되지 않았습니다.

출처 COCI 2020/2021 Contest 1

평가 및 의견

Papricice

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Papricice

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