天天看點

poj3469(最大流最小割問題)

題目連結:http://poj.org/problem?id=3469

Dual Core CPU

Time Limit: 15000MS

Memory Limit: 131072K

Total Submissions: 18147

Accepted: 7833

Case Time Limit: 5000MS

Description

As more and more computers are equipped with dual core CPU, SetagLilb, the Chief Technology Officer of TinySoft Corporation, decided to update their famous product - SWODNIW.

The routine consists of N modules, and each of them should run in a certain core. The costs for all the routines to execute on two cores has been estimated. Let‘s define them as Ai and Bi. Meanwhile, M pairs

of modules need to do some data-exchange. If they are running on the same core, then the cost of this action can be ignored. Otherwise, some extra cost are needed. You should arrange wisely to minimize the total cost.

Input

There are two integers in the first line of input data, N and M (1 ≤ N ≤ 20000, 1 ≤ M ≤ 200000) .

The next N lines, each contains two integer, Ai and Bi.

In the following M lines, each contains three integers: a, b, w. The meaning is that if module a and module b don‘t execute on the same core, you should pay extra w dollars for the data-exchange

between them.

Output

Output only one integer, the minimum total cost.

Sample Input

Sample Output

Source

, Zhou Dong

[]   []   []  

[]

一道典型的最小割問題。

我們先假定兩個額外的點,源點s,和彙點t。 我們記圖中 s-t 割所對應的包含s的頂點集合為S,包含t集合為T。

對于頂點屬于S時所産生的費用,隻要從每個子產品向t連一條容量為A[i]的邊就可以對應起來,對于屬于T的,隻要從s向每個子產品連一條容量為B[i]的邊即可,接下對那些a[i]屬于S,b[i]屬于T時所産生的費用,隻要從子產品a[i]向子產品b[i]連一條容量為w[i]的邊就可以對應,對剩餘情況同理可得。

code: