Logo
(追記) (追記ここまで)

28484번 - Garden 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.8 초 1024 MB162110.000%

문제

Sashka is responsible for the maintenance of the flowers in the city garden. The garden consists of $N$ flower beds, numbered with the integers from 1ドル$ to $N,ドル where some of the flower beds are connected by pipes. The beds and the pipes form a connected, acyclic, undirected graph, in which the flower beds are the nodes and the pipes – the edges. In each bed there is an installed pump which can pump water from the underground. This water irrigates the bed in which the pump is located and sends water through the pipes to some of the beds that have a path of pipes to them. The pumps are numbered from 1ドル$ to $N,ドル with one pump’s number being equal to the number of the bed it is located in. If the pump located in a bed with number $x$ (1ドル ≤ x ≤ N$) works for $p$ minutes, the water will reach all beds that have distance within $p - 1$ edges from $x$ in the acyclic graph. The system of pumps is such that one pump runs first, then another one and so on. Two pumps never work simultaneously. A pump can run only once. A flower bed is considered irrigated if water has reached it, regardless of which pump. The pumps are designed in such a way, that if a pump with number $m$ runs, it should run at most $t_m$ minutes, otherwise it can malfunction. A run of a pump must continue an integer number of minutes. The pumps are identical and consume electricity as follows: 1ドル$ minute run costs $c_1$ euro, 2ドル$ minute run costs $c_2$ euro and so on. If a pump doesn’t run, it won’t consume electricity. Sashka is given the task of determining the minimum amount of money for electricity, when an appropriate set of pumps runs, so all the flower beds can be irrigated.

Write a program garden, which solves the task Sashka is given.

입력

The first line of the standard input contains an integer $N,ドル equal to the number of beds (and pumps) in the garden. The second line contains also $N$ non-negative integers $c_1, c_2, \dots , c_N,ドル separated by intervals – the money for electricity, which a pump consumes for respectively 1,2,ドル \dots , N$ minute run. The third line contains $N$ non-negative integers $t_1,t_2, \dots ,t_N,ドル separated by intervals – the maximum allowed run time for each pump. If some of these integers is equal to 0ドル,ドル this means that the respective pump cannot be used. Each of the last $N - 1$ lines of the standard input contains two positive integers $u$ and $v,ドル defining a pipe (edge) connecting the beds with numbers $u$ and $v$. It’s guaranteed that the flower beds and the pipes, connecting them, form a connected, acyclic graph.

출력

On the only line of the standard output, the program should output the minimum amount of money for electricity so all the flower beds can be irrigated. If it’s impossible to irrigate all the flower beds, your program should output $-1$.

제한

  • 1ドル ≤ N ≤ 2,000円$
  • 0ドル ≤ c_i ≤ 10^6$
  • 0ドル ≤ t_i ≤ N$

서브태스크

번호배점제한
111

$N \le 8$

212

$N \le 75,ドル The graph is a chain.

311

$N \le 500,ドル The graph is a chain.

413

$N \le 2,000円,ドル The graph is a chain.

517

$N \le 75$

614

$N \le 500$

722

$N \le 2,000円$

A graph is a chain if and only if each node has at most 2 neighbors and there are exactly 2 vertices with 1 neighbor.

예제 입력 1

8
1 4 9 16 25 36 49 64
1 5 1 1 0 0 5 0
1 2
2 3
1 4
2 5
2 6
4 7
7 8

예제 출력 1

8

An irrigation with a minimum amount of money is achieved when pump No2ドル$ runs for 2ドル$ minutes and pump No7ドル$ runs for 2ドル$ minutes. The consumed electricity will cost $c_2 + c_2 = 4 + 4 = 8$ euro.

예제 입력 2

7
1 4 9 16 25 36 49
0 5 5 0 0 0 0
1 2
2 4
1 3
1 5
3 7
3 6

예제 출력 2

13

An irrigation with a minimum amount of money is achieved when pump No3ドル$ runs for 3ドル$ minutes and pump No2ドル$ runs for 2ドル$ minutes. The consumed electricity will cost $c_2 + c_3 = 4 + 9 = 13$ euro.

노트

A graph is a chain if and only if each node has at most 2 neighbors and there are exactly 2 vertices with 1 neighbor.

출처

Olympiad > International Autumn Tournament in Informatics > 2022 > Group B (Juniors) 2번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /