编程介的小学生 2019-08-29 23:50 采纳率: 20.5%
浏览 91

C语言,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

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)