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

Paprike

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

의견: 0

설명

Krešo went to a local family farm and bought a bunch of hot peppers that are neatly connected with pieces
of string into a \(so-ca\)lled wreath. In this task, a wreath consists of \(n\) peppers and (\(n - 1\)) pieces of string.
Each piece of string connects two different peppers, and each two peppers in the wreath are connected
(directly or indirectly) by the string. Therefore, the peppers and pieces of string form a \(so-ca\)lled tree.
Making one cut with scissors, Krešo can cut the string, and split a pepper wreath into two smaller wreaths,
which can again be split into smaller wreaths, and so on. Notice that a single pepper not connected to
anything also forms a wreath.
Figure 1: The initial wreaths from the first two test cases together with the optimal cuts.
The spiciness of a single peper is measured using the \(so-ca\)lled Scoville scale, and is represented as a
n\(on-ne\)gative integer. The spiciness of the wreath is the sum of spiciness of individual peppers it contains.
Krešo wants to spice up the lunch of high school students after an informatics competition and knows
that the average high school student can eat a wreath whose spiciness is at most \(k\) before they need to
ask for a doctor and a juvenile lawyer.
Determine the minimal number of cuts needed so that Krešo can split the initial wreath into wreaths with
spiciness at most \(k\).

제약

In all subtasks, it holds \(n \ge 2\) i \(0 \le h_{1}\), h_{2}, . . . , \(h_{n} \le k \le 3\,000\,000\).
Subtask Score Constraints
1
11
\(n \le 15\)
2
13
\(n \le 100\,000\), each pepper \(x = 1\), . . . , \(n - 1\) is connected to pepper \(x + 1\).
3
27
\(n \le 1\,000\)
4
49
\(n \le 100\,000\)

입력 형식

The first line of input contains the integers \(n\) and \(k\) — the number of peppers and the maximal allowed
spiciness of an individual wreath. The peppers are denoted with numbers from 1 to \(n\). The following line
contains \(n\) integers \(h\)1, h2, . . . , h\(n\) — the number \(hj\) is the spiciness of pepper \(j\). Each of the following
\(n - 1\) lines contains two distinct integers \(x\) and \(y\) (\(1 \le x\), \(y \le n\)) — the labels of the peppers directly
connected with a piece of string in the initial wreath. The peppers and strings form a tree, as described
in the task.

출력 형식

You must output the minimal number of cuts.

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

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

출처 COCI 2017/2018 Olympiad

평가 및 의견

Paprike

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

Log in to rate problems.

개별 의견

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

풀이 제출

Paprike

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