### 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.

3 1
1 10
2 10
10 3
2 3 1000

13

### Source

POJ Monthly--2007.11.25, Zhou Dong

### Solution

1. 指定超级源S=0,超级汇T=n+1
2. 对于每一个节点,$S\rightarrow i$连边,权值为ai
3. 对于每一个节点,$i\rightarrow T$连边,权值为bi
4. 对于节点间有相互关系的节点 i , j ,$i\leftrightarrow j$连边,权值为w

### Code

#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cstdio>
#define maxn 22000
#define maxe 1000010
#define INF 0x7f7f7f7f
#define DEBUG
using namespace std;
int n,m,cnt=1,T;

struct edge
{
int to,next,val;
}e[maxe];

{
char ch;
do
ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-');
if(ch=='-') sign=-1,ch=getchar();
while(ch>='0'&&ch<='9')
{
ch=getchar();
}
}

inline void ins(int u,int v,int w)
{
cnt++;
e[cnt].to=v;
e[cnt].val=w;
}

inline void insert(int u,int v,int w)
{ ins(u,v,w),ins(v,u,0); }

bool bfs()
{
memset(dis,-1,sizeof(dis));
queue<int> q;
q.push(0);
dis[0]=0;
while(!q.empty())
{
int u=q.front();q.pop();
while(i)
{
if(e[i].val && dis[e[i].to]==-1)
q.push(e[i].to),dis[e[i].to]=dis[u]+1;
i=e[i].next;
}
}
if(dis[T]==-1) return 0;
return 1;
}

int dfs(int x,int flow)
{
if(x==T) return flow;
while(i)
{
if(e[i].val && dis[e[i].to]==dis[x]+1)
{
w=flow-used;
w=dfs(e[i].to,min(w,e[i].val));
e[i].val-=w;
e[i^1].val+=w;
used+=w;
if(used==flow) return flow;
}
i=e[i].next;
}
if(!used) dis[x]=-1;
return used;
}

int dinic()
{
int ans=0;
while(bfs()) ans+=dfs(0,INF);
return ans;
}

int main()
{
for(int i=1;i<=n;++i)
{
insert(0,i,a);
insert(i,T,b);
}
for(int i=1;i<=m;++i)
{
int u,v,w;