Valley of Peace is not only famous for Inner Peace but also well known for the delicious pizzas of Mr. Ping, the goose father of legendary Kung Fu Panda Po.
The delicious pizza of Mr. Ping has become so much famous that the demand of it has increased to a great extent. Mr. Ping wants to deliver his pizzas to Gongmen City which is ruled by Evil Lord Shen. Wolf bandits are guarding the Gongmen City and everywhere else. So, there are some fixed allowable amounts of pizza Ck that can be carried through kth road. For some reason, the roads are one way only. Assume that there are N cities, Valley of Peace is the 1st city and Gongmen City is the Nth city.
Mr. Ping along with Master Shifu has calculated the demands for each city and a least amount of pizzas Lk (≤ Ck) for kth road that must be sent to satisfy the demands. Mr. Ping always wanted Po to become a great chef like him but Panda Po was busy practicing Kung Fu. So, now Mr. Ping has given him the job to deliver pizzas to Gongmen City fulfilling the requirements stated above.
Po along with his team cannot carry more or not even less than allowable amount assigned for each road, otherwise Stealth Mode will be broken and they will get caught. If the amount of pizzas going through the road from ith city to jth (1 < i, j < N) city is Fij, then for each i, the following condition must hold:
$$\sum_{i=1}^N F_{ij} = \sum_{i=1}^N F_{ji}$$
Po is very excited to complete this awesome task along with Thundering Rhino and all helping hands possible. As you are a good friend of Panda; he wanted your help to know if it is possible to get this job done.
Input
Input starts with an integer T (≤ 20), denoting the number of test cases.
Each case starts with a blank line. Next line contains two integers N (2 ≤ N ≤ 200) and M where N denotes the number of cities and M denotes the number of unidirectional roads. The kth line of the next M lines contains four integers uk vk Lk Ck (1 ≤ uk < N and 1 < vk ≤ N, uk ≠ vk, 0 ≤ Lk ≤ Ck ≤ 105) meaning that there is a road from city uk to vk, and at least Lk units of pizza must be sent through this road but not exceeding Ck units. There can be at most one road from a city u to v and from any city u, it's impossible to return to u visiting other cities.
Output
For each case, print the case number and yes
if it's possible to deliver the pizzas maintaining the restrictions, or no
otherwise. If it's possible to do so, print extra M lines, where the kth line should contain the amount of pizza that should be sent through the kth road. There can be multiple solutions, report any valid one.
Sample
Sample Input | Sample Output |
---|---|
5 2 1 1 2 5 10 4 5 1 2 3 4 1 3 2 3 3 2 2 5 3 4 2 3 2 4 4 10 4 5 1 2 3 5 1 3 2 10 3 2 2 5 3 4 2 3 2 4 6 10 5 4 1 4 5 5 4 2 3 5 2 3 3 5 3 5 0 10 5 5 1 4 5 5 4 2 3 5 2 3 3 5 3 5 0 10 1 5 0 10 | Case 1: yes 5 Case 2: no Case 3: yes 4 4 2 2 6 Case 4: yes 5 5 5 5 Case 5: yes 5 5 5 5 0 |
Notes
- Dataset is huge, use faster I/O methods.
- This is a special judge problem; wrong output format may cause 'Wrong Answer'.