
ZOJ Problem Set  2332
Wealthy alsomagic! alsomagic has a lot of gems with different colors and shapes. His supernatural power provides him the ability of transforming some gems' shape and color! Now he wants to give some of gems to his darling girlfriend as gift. But a problem came with him. His girlfriend dislikes too many gems with the same color! And alsomagic, will also be disgusted with lots of gems with the same shape. So he attempts to change some gems to solve this problem. Input The first line of a multiple input is an integer T, followed by T input blocks. The first line of each input block are two integers N, M (1 =< N,M <= 10) indicating alsomagic has N different shapes of gems with M different colors, then N lines of integers follow, each line contains M integers. The integer K in row R column C states that alsomagic has K number of gems with shape R and color C. Follow this is integer D, then D lines of integers. Each line contains four integers R1��C1��R2��C2(0 =< R1, R2 < N, 0 <= C1, C2 < M) indicating one kind of transfor way, by which he can change some of shape R1, color C1 gems to shape R2, color C2, and VICE VERSA. But each way of transform can only be used ONCE! Then N integers, the Kth integer is the number of gems with SHAPE K that alsomagic can tolerance. Output One line percase, with ��Yes�� if there is a way to solve this problem, otherwise ��No��. Sample Input 21 3 3 2 6 1 0 1 0 2 5 1 3 2 1 3 3 2 6 1 0 1 0 2 4 1 3 2 Sample Output YesNo
Special thanks to: Author: LIU, Yaoting Source: ZOJ 3rd Anniversary Contest 