编程介的小学生 2019-08-26 21:55 采纳率: 20.5%
浏览 121

Everyone Has His Wing Broken

Problem Description
Long long ago, N gamblers (numbered from 1 to N) got together to gamble. At that time, the kinds of gamble were not that much diversified. The gamble can only be performed in a way that two people played against each other and the one who lost the game would have to give the winner 1.Furthermore,theonewholoseallhismoneyandloseforanothertimewouldgetoutandnevercomeback.Buthestillhastopay1 (He may sell his pants). After playing for quite a long time, they felt as if they had their wings broken, for everyone still here won nothing.
As one of the gamblers, mzry1992 wondered what really happened. Now mzry1992 wants you to tell him what happened between some pairs, for example how much does gambler A win from gambler B directly. But actually you do not know the real situation. So you could just tell him one of the possible situations.

Input
There are T cases and the first line of the input contains the number T. The first line of each case consists of one integer N(2 ≤N≤500), indicating the number of gamblers. Then comes N lines. The i-th line is a non-negative integer smaller than 101 indicating the i-th gambler's initial possess. The next line contains one integer M(0≤M≤10000), indicating the number of pairs of gamblers who gambled. The following M line contains three integer A, B, t(1≤A, B≤N, 1≤t≤100), which means that the gamble A and the gamble B played the game for t times. The final part of each test case begins with an integer Q (1≤Q≤200000). Then Q lines follows. Each line contains two integers A, B. You are asked to answer how much gambler A wins from B.

Output
Output the all the queries from mzry1992.For each test case, your answer should assume that all of the gambles could happen in the one situation. If there is no such situation, just output “Impossible!.

Sample Input
3
3
7
5
9
3
1 2 7
1 3 5
2 3 9
1
1 2

3
1
1
20
1
1 2 2
2
1 2
1 3

3
1
1
20
1
1 2 3
2
1 2
1 3

Sample Output
Case 1:
-5
Case 2:
0
0
Case 3:
Impossible!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮