编程介的小学生 2017-04-03 12:15 采纳率: 20.5%
浏览 779
已采纳

Gems

Wealthy alsomagic!
Supernatural alsomagic!
But also poor alsomagic!
Because he is now puzzled by a problem, and will go crazy if you can��t help him.

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 K-th integer is the number of gems with SHAPE K that alsomagic can tolerance.
Then M integers. The K-th integer is the number of gems with COLOR K that alsomagic��s girlfriend can tolerance!

Output

One line percase, with ��Yes�� if there is a way to solve this problem, otherwise ��No��.

Sample Input
2

1 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
Yes
No

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-04-16 15:32
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python