编程介的小学生 2019-01-07 16:55 采纳率: 20.5%
浏览 506
已采纳

C语言旅行商遍历问题,旅行问题,采用C语言怎么解决?

Problem Description
When Wiskey return home, many relatives he need to visit, and he will buy some gifts before he visit his relatives. There is a map which has N places; Wiskey's house is labeled 0. He has T tasks which from u to v, it mean Wiskey could go to v when he bought a gift at u before.
Wiskey always start at 0, and must end with 0.
Tell him how many minimum total places he went when he finished all tasks.

Input
First line will contain one integer mean how many cases will follow by; the number of cases wills less than 20.
In each case will contain three integers N means the number of places, M roads and T tasks. (1 <= N <= 20, 0 <= M <= 100, 0 <= T <= 5).
First, M roads will be follow; the road is bi-connected.
Second, T tasks will be follow; you are remember the u must went earlier than v, then what makes the task will be finished.

Output
Print the minimum total number of places he went.
If Wiskey can't finish all tasks, please print -1.

Sample Input
1
7 11 5
0 1
0 2
1 2
1 4
0 3
3 4
4 6
2 6
6 5
3 5
4 5
1 2
1 3
2 0
1 4
5 3

Sample Output
7

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-12-17 23:27
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形