2020牛客暑期多校训练营(第五场)——A Portal

本文介绍了一道编程题目,涉及在带有边长的图中完成任务的问题。通过建立和关闭传送门来减少行走距离,目标是找到完成所有任务所需的最短路径。文章提供了输入输出描述、样例及题解,解释了如何用动态规划策略来求解问题。
摘要由CSDN通过智能技术生成

2020牛客暑期多校训练营(第五场)——A Portal

题目描述

You are now in a big factory. The factory could be recognized as a graph with n vertices and m edges. Every edge has its length. You have k missions to do. The ith mission is going to vertex ai, picking a block and then sending it to vertex bi . You should complete the missions in the order from 1st to kth. Initially you are standing at vectex 1.

You have a gun in your hand. When you are at some vertex u, you could shoot the gun at the ground, and then a portal will be built at vertex u. When there are two portals in the factory, assuming they are at u and v, you could transfer between u and v with no cost(just like an edge connecting u and v with length 0).

You also have a remote controller in your hand. It allows you to close a portal whenever you want and wherever you are(closing one portal at a time, not all portals at the same time). What’s more, there could be at most two existing portals. So if you want to create another portal when there exists two, you must use your controller to close one before you create.

You need to find the minimum distance you have to walk in order to complete all k missions.

输入描述

在这里插入图片描述

输出描述

Output one integer indicating the minimum distance.

样例输入

输入1

5 4 2
1 2 1
2 3 1
3 4 1
4 5 1
1 5
2 4

输入2

6 10 3
1 1 6
5 6 9
3 5 8
1 4 1
2 4 7
6 6 10
1 4 2
6 5 10
3 5 2
3 1 9
1 5
2 5
4 3

输入3

6 10 3
1 1 3
3 1 1
6 2 3
1 6 10
4 1 1
3 1 2
5 6 9
5 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值