编程介的小学生 2019-06-11 10:57 采纳率: 20.5%
浏览 91

路径的有效查找的算法问题,怎么使用C语言的程序编写程序的办法去加以实现的方式是什么

Problem Description
Scofield is a hero in American show "Prison Break". He had broken the prison and started a big runaway.
Scofield has a map of US with cities and bidirectional roads between them. The lengths of roads are known. Some cities get a lot of cops who are very troublesome. Now Scofield needs your help to arrange his runaway route.

He needs a shortest path between two cities, while the quantity of the police in any city, except the start city and end city, on the route is no more than k.

You should know that it is very hard to escape. Scofield is very smart but not good at computer. Now Scofield is in trouble, can you help him with your computer?

Input
The input consists of several test cases. There is an integer T on the first line indicating the number of test cases.
For each case, the first line consists of two integers N and M. N is the number of cities; M is the number of roads. The next line contains N integers C1, C2... CN, where Ci is the number of cops in city i.

Then followed M lines, each line consists of three integer, u, v, w, indicating there is a road with length w between city u and city v.

The following line consists of an integer Q, indicating the number of queries. Each of the following Q lines consists of three integers, u, v, k, indicating the query for the shortest path between city u and city v with limitation of k cops.

Technical Specification

  1. T ≤ 20
  2. 2 ≤ N ≤ 200, 0 ≤ M ≤ n * (n – 1) / 2
  3. 0 ≤ Ci ≤ 1000,000,000
  4. 0 ≤ u, v < N, 0 ≤ w ≤ 1000, 0 ≤ k ≤ 1000,000,000
  5. 0 ≤ Q ≤ 100000
  6. There is no more than ONE road between two cities and no road between the same cities.
  7. For each query, u is not equal to v.
  8. There is ONE empty line after each test case.

Output
For each query, output a single line contains the length of the shortest path. Output "-1" if you can't find the path. Please output an empty line after each test case.

Sample Input
1
4 4
100 2 3 100
0 1 1
0 2 1
1 3 2
2 3 3
2
0 3 2
0 3 1

Sample Output
3
-1

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能