编程介的小学生 2017-03-24 12:13 采纳率: 20.5%
浏览 755
已采纳

Cells

Scientists are conducting research on the behavior of a newly discovered Agamic Cellular Microbe. This special kind of microbe is capable of massively reproducing by itself in a short time. The lifetime of an ACM consists of three phases:
1. The infancy phase, which starts from its birth and lasts for approximately several seconds;
2. The multiplication phase, in which one ACM can procreate up to 100 offspring in only several milliseconds;
3. The mature phase, in which it remains inactive for the rest of its life.
At the beginning of the experiment, a newborn, single cell of ACM, is put into a suitable circumstance for its production. This cell, numbered as 0, starts to multiply and its descendants are numbered, starting from 1, according to their positions in the family hierarchy. During the experiment special equipment is used to record the numbers of the offspring generated by each of the ACM's. The experiment is stopped after a certain time period.

The family tree of ACM's in the first case of sample input
Your task is to help the scientists to determine whether one ACM is an ancestor of another.

Input Description

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 10) which is the number of test cases. T test cases follow, each preceded by a single blank line.

Each test case starts with a single integer N (1 <= N <= 300,000) which is the number of ACM's that have their descendants recorded. The following N integers (not necessarily on a same line), Ci (0 <= i < N, 0 <= Ci <= 100), give the number of offspring of the i-th ACM. The next line contains an integer M (1 <= M <= 1,000,000) which is the number of queries. M lines follow, each contains two integers a and b, querying whether the a-th ACM is an ancestor of the b-th ACM.

The total number of ACM's may be greater than N, but would never exceed 20,000,000.

Output Description

Results should be directed to standard output. Start each case with "Case #:" on a single line, where # is the case number starting from 1. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.

For each query, print either "Yes" or "No" on a single line, which is the answer to the query.

Sample Input

2

6
3 2 1 1 0 2
5
0 1
2 4
3 5
1 8
6 9

5
2 0 3 0 1
4
2 6
1 6
2 3
3 5
Sample Output

Case 1:
Yes
No
No
Yes
No

Case 2:
Yes
No
Yes
No

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-04-01 15:12
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用