编程介的小学生 2017-08-25 07:56 采纳率: 20.5%
浏览 816
已采纳

GRE Words Once More!

Problem Description
Now Matt is preparing for the Graduate Record Examinations as Coach Pang did in 2013 and George did in 2011.

Thanks to modern techniques, Matt uses automata instead of old-fasioned vocabulary books.

The automata used by Matt is a directed acyclic graph (DAG) with N vertices and M edges. The vertices are conveniently numbered by 1, 2, . . . , N . Each edge is labeled with an integer. Additionally, some vertices are marked as special.

A GRE word is obtained by concatenating the labels on the path from vertex 1 to a special vertex.

Now, Matt has Q questions. The i-th question is asking for the length of ki-th smallest words among all the GRE words he can obtain in lexicographical order.

Input
The first line contains only one integer T , which indicates the number of test cases.

For each test case, the first line contains three integers N, M, Q (2 ≤ N ≤ 105, 0 ≤ M ≤ 105, 1 ≤ Q ≤ 105).

The second line contains N - 1 integers s2, . . . , sn. If the i-th vertex is special, then si = 1. Otherwise, si = 0. Vertex 1 is never special.

Each of the following M lines contains three integers ai, bi, ci denoting an edge from vertex ai to vertex bi labeled with ci (1 ≤ ai, bi ≤ N, 1 ≤ ci ≤ 109). For each vertex v, all outgoing edges are labeled with distinct integers.

Each of the following Q lines contains the integer ki (1 ≤ ki ≤ 108) of the i-th question.

Output
For each test case, output “Case #x:” in the frirst line, where x is the case number (starting from 1).

Then, for each question, output the length of the word in one line. If the word does not exist, output “-1” (without quotes) instead.

Sample Input
1
3 3 4
1 1
1 2 1
1 3 12
2 3 3
1
2
3
4

Sample Output
Case #1:
1
2
1
-1

  • 写回答

2条回答 默认 最新

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

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘