|
||||||||||
Base StationTime Limit: 5000/2000 MS (Java/Others) Memory Limit: 65768/32768 K (Java/Others)Total Submission(s): 3281 Accepted Submission(s): 1360 Problem Description A famous mobile communication company is planning to build a new set of base stations. According to the previous investigation, n places are chosen as the possible new locations to build those new stations. However, the condition of each position varies much, so the costs to built a station at different places are different. The cost to build a new station at the ith place is Pi (1<=i<=n). When complete building, two places which both have stations can communicate with each other. Besides, according to the marketing department, the company has received m requirements. The ith requirement is represented by three integers Ai, Bi and Ci, which means if place Ai and Bi can communicate with each other, the company will get Ci profit. Now, the company wants to maximize the profits, so maybe just part of the possible locations will be chosen to build new stations. The boss wants to know the maximum profits. Input Multiple test cases (no more than 20), for each test case: The first line has two integers n (0<n<=5000) and m (0<m<=50000). The second line has n integers, P1 through Pn, describes the cost of each location. Next m line, each line contains three integers, Ai, Bi and Ci, describes the ith requirement. Output One integer each case, the maximum profit of the company. Sample Input
Sample Output
Author liulibo Source | ||||||||||
|