MTELE - Tele Broadcast

A TV-network plans to broadcast an important football match. Their network of transmitters and users can be represented as a tree. The root of the tree is a transmitter that emits the football match, the leaves of the tree are the potential users and other vertices in the tree are relays (transmitters). The price of transmission of a signal from one transmitter to another or to the user is given. A price of the entire broadcast is the sum of prices of all individual signal transmissions. Every user is ready to pay a certain amount of money to watch the match and the TV-network then decides whether or not to provide the user with the signal. Write a program that will find the maximal number of users able to watch the match so that the TV-network’s doesn’t lose money from broadcasting the match.

Input

The first line of the input file contains two integers N and M, 2 ≤ N ≤ 3000, 1 ≤ M ≤ N-1, the number of vertices in the tree and the number of potential users. The root of the tree is marked with the number 1, while other transmitters are numbered 2 to N-M and potential users are numbered N-M+1 to N. The following N-M lines contain data about the transmitters in the following form: K A1 C1 A2 C2 ... AK CK Means that a transmitter transmits the signal to K transmitters or users, every one of them described by the pair of numbers A and C, the transmitter or user’s number and the cost of transmitting the signal to them. The last line contains the data about users, containing M integers representing respectively the price every one of them is willing to pay to watch the match.

Output

The first and the only line of the output file should contain the maximal number of users described in the above text.

Sample

Input:
5 3
2 2 2 5 3
2 3 2 4 3
3 4 2

Output:
2
Input:
5 3
2 2 2 5 3
2 3 2 4 3
4 4 2

Output:
3
Input:
9 6
3 2 2 3 2 9 3
2 4 2 5 2
3 6 2 7 2 8 2
4 3 3 3 1 1

Output:
5

Được gửi lên bởi:psetter
Ngày:2009-03-20
Thời gian chạy:0.100s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET
Nguồn bài:COI 02

hide comments
2010-09-13 14:05:13 Siêu Nhân Trong Suốt
Chạy Time gì vừa khít 5s ? nhìn ảo quá
2010-09-13 10:02:46 Cao Viên Viên
3,77 s :((
2010-09-12 14:46:36 Siêu Nhân Trong Suốt
Vì giới hạn cho như thế là đủ

Last edit: 2010-09-12 14:46:52
2010-09-12 14:41:49 Cao Viên Viên
sao chẳng cho giới hạn gì hết vậy
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.