|
||||||||||
Road constructionsTime Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1939 Accepted Submission(s): 669 Problem Description N cities are required to connect with each other by a new transportation system. After several rounds of bidding, we have selected M constructions companies and decided which section is assigned to which company, the associated cost and the direction of each road. Due to the insufficiency of national fiscal revenue and special taxation system £¨the tax paid by each company pays is a fixed amount and tax payment occurs at the beginning of the construction of the project£© The government wishes to complete the project in several years and collects as much tax as possible to support the public expense For the restrictions of construction and engineering techniques, if a company is required to start the construction, then itself and its associated companies have to complete all the tasks they commit (if company A constructs a road from city 1 to city 2, company B constructs a road from city 2 to city 3, company C constructs a road from city 1 to city 3, we call companies A and B are associated and other company pairs have no such relationship, pay attention, in this example and a are not associated, in other words,¡¯ associated' is a directed relationship). Now the question is what the maximum income the government can obtain in the first year is£¿ Input There are multiple cases (no more than 50). Each test case starts with a line, which contains 2 positive integers, n and m (1<=n<=1000, 1<=m<=5000). The next line contains m integer which means the tax of each company. The Third line has an integer k (1<=k<=3000)which indicates the number of the roads. Then k lines fellow, each contains 4 integers, the start of the roads, the end of the road, the company is responsible for this road and the cost of the road. The end of the input with two zero Output For each test case output the maximum income in a separate line, and if you can not get any income, please output 0. Sample Input
Sample Output
Hint for second test case, if you choose company 2 responsible ways, then you must choose the path of responsible company 1, but if you choose company 1, then you do not have to choose company 2. Source | ||||||||||
|