Balance

题意翻译

有 $n$ 个水桶编号为 $1$~$n$,每个水桶的容量为整数 $v$。水桶之间有 $e$ 条双向管道(可能重复),一次操作可以从一个水桶通过管道输送任意非负整数量的水到另一个水桶,但要保证任意时刻水桶中的水量不超过容量。现给定一个初始局面 $\big<a_i\big>$(表示第 $i$ 个水桶的水量为 $a_i$ )和一个目标局面$\big<b_i\big>$,问是否可以在 $2n^2$ 次操作内从初始局面到达目标局面。如果可以输出方案,否则输出 `NO`。 $1\le n \le300,1\le v \le 10^9,0\le e \le50000$ $0\le a_i,b_i\le v$

题目描述

A system of $ n $ vessels with water is given. Several pairs of vessels are connected by tubes with transfusion mechanisms. One may transfer an integer amount of liters of water between two vessels connected by such tube (tube works in both directions). There might be multiple tubes between two vessels. Total number of tubes equals $ e $ . Volume of each vessel equals $ v $ liters. Of course, the amount of the water in any vessel cannot exceed $ v $ liters in the process of transfusions. Given the initial amounts $ a_{i} $ of water in the vessels and the desired amounts $ b_{i} $ find a sequence of transfusions that deals with the task. Total number of transfusions must not exceed $ 2·n^{2} $ .

输入输出格式

输入格式


First line of the input contains integers $ n $ , $ v $ , $ e $ ( $ 1<=n<=300 $ , $ 1<=v<=10^{9} $ , $ 0<=e<=50000 $ ). Next two lines contain $ n $ integers each: initial $ a_{i} $ and the desired amounts $ b_{i} $ of water in corresponding vessels ( $ 0<=a_{i},b_{i}<=v $ ). Next $ e $ lines describe one tube each in the format $ x $ $ y $ ( $ 1<=x,y<=n,x≠y $ ) for a tube between vessels number $ x $ and $ y $ . There might be multiple tubes between two vessels. You may assume that vessels are numbered from 1 to $ n $ in some way.

输出格式


Print "NO" (without quotes), if such sequence of transfusions does not exist. Otherwise print any suitable sequence in the following format. On the first line print the total number of transfusions $ k $ ( $ k $ should not exceed $ 2·n^{2} $ ). In the following $ k $ lines print transfusions in the format $ x $ $ y $ $ d $ (transfusion of $ d $ liters from the vessel number $ x $ to the vessel number $ y $ , $ x $ and $ y $ must be distinct). For all transfusions $ d $ must be a non-negative integer.

输入输出样例

输入样例 #1

2 10 1
1 9
5 5
1 2

输出样例 #1

1
2 1 4

输入样例 #2

2 10 0
5 2
4 2

输出样例 #2

NO

输入样例 #3

2 10 0
4 2
4 2

输出样例 #3

0