2014 + schools 9 (1007) hdu4966 (minimum tree structure)

Source: Internet
Author: User
GGS-DDU Time Limit: 2000/1000 MS (Java/others) memory limit: 131072/131072 K (Java/Others)
Total submission (s): 324 accepted submission (s): 171


Problem descriptiondo you think this is a strange problem name? That is because you don't know its full name --- 'good good study and day up! ". Very famous sentence! Isn' t it?

Now "GGS-DDU" is lzqxh's target! He has n courses and every course is divided into a plurality of levels. Just like college English have level 4 and Level 6.

To simplify the problem, we suppose that the I-th course has levels from level 0 to level a [I]. and at the beginning, lzqxh is at level 0 of every course. because his target is "GGS-DDU", lzqxh wants to reach the highest level of every course.

Fortunately, there are m tutorial classes. the I-th tutoial class requires that students must reach at least level L1 [I] Of course C [I] Before class begins. and after finishing the I-th tutorial class, the students will reach level L2 [I] Of course d [I]. the I-th tutoial class costs lzqxh money [I].

For example, there is a tutorial class only students who reach at least level 5 of "tiyu" can apply. and after finishing this class, the student's "meishu" will reach level 10 if his "meishu"'s level is lower than 10. (Don't ask me why! Supernatural class !!! ")

Now you task is to help lzqxh to compute the minimum cost!
Inputthe input contains multiple test cases.

The first line of each case consists of two integers, n (n <= 50) and M (M <= 2000 ).
The following line contains N integers, representing a [1] to a [n]. The sum of a [1] to a [n] will not exceed 500.
The next M lines, each have five integers, indicating C [I], L1 [I], d [I], l2 [I] and money [I] (1 <= C [I], d [I] <= n, 0 <= L1 [I] <= A [C [I], 0 <= L2 [I] <= A [d [I], money [I] <= 1000) for the I-th tutorial class. the courses are numbered from 1 to n.

The input is terminated by N = m = 0.
Outputoutput the minimum cost for achieving lzqxh's target in a line. If his target can't be achieved, just output-1.
Sample Input
3 43 3 11 0 2 3 102 1 1 2 101 2 3 1 103 1 1 3 100 0
 
Sample output
40

Question: I have given n subjects and the grades required for each subject. Then I have given m classes and the grades required for each course, after the course is completed, you can obtain the level of the subject and the cost of the course, and then find the minimum cost for each course to reach the full level. If not, output-1
Train of Thought: will each subject each level as a point, then for the same subject, Level I to the level I-1 connected to one side, the cost is 0, then give the M class course, from the required subject Level I to the available subject level J
Edge, the cost is the given cost. Scale the level 0 of all courses into a root node, and then the problem is converted to the minimum tree structure, also called the minimum spanning tree on the directed graph ~

2014 + schools 9 (1007) hdu4966 (minimum tree structure)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.