欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1915G.Bicycles
Bicycles
CF1915G · Bicycles
- 难度:1800
- 标签:graphs、greedy、implementation、shortest paths、sortings
- 链接:https://codeforces.com/problemset/problem/1915/G
- 时间限制:4 seconds 内存限制:256 megabytes
- 出现位置:Day29-阶段模拟8-高压综合卷
英文原题面
Statement
All of Slavic's friends are planning to travel from the place where they live to a party using their bikes. And they all have a bike except Slavic. There are cities through which they can travel. They all live in the city and want to go to the party located in the city . The map of cities can be seen as an undirected graph with nodes and edges. Edge connects cities and and has a length of . Slavic doesn't have a bike, but what he has is money. Every city has exactly one bike for sale. The bike in the -th city has a slowness factor of . Once Slavic buys a bike, he can use it whenever to travel from the city he is currently in to any neighboring city, by taking time, considering he is traversing edge using a bike he owns. Slavic can buy as many bikes as he wants as money isn't a problem for him. Since Slavic hates traveling by bike, he wants to get from his place to the party in the shortest amount of time possible. And, since his informatics skills are quite rusty, he asks you for help. What's the shortest amount of time required for Slavic to travel from city to city ? Slavic can't travel without a bike. It is guaranteed that it is possible for Slavic to travel from city to any other city.
Input
The first line contains a single integer () — the number of test cases. The description of the test cases follows. The first line of each test case contains two space-separated integers and (; ) — the number of cities and the number of roads, respectively. The -th of the following lines each contain three integers , , (, ; ), denoting that there is a road between cities and of length . The same pair of cities can be connected by more than one road. The next line contains integers () — the slowness factor of each bike. The sum of over all test cases does not exceed , and the sum of over all test cases does not exceed . Additional constraint on the input: it is possible to travel from city to any other city.
Output
For each test case, output a single integer denoting the shortest amount of time Slavic can reach city starting from city .
样例
样例 1
输入:
3
5 5
1 2 2
3 2 1
2 4 5
2 5 7
4 5 1
5 2 1 3 3
5 10
1 2 5
1 3 5
1 4 4
1 5 8
2 3 6
2 4 3
2 5 2
3 4 1
3 5 8
4 5 2
7 2 8 4 1
7 10
3 2 8
2 1 4
2 5 7
2 6 4
7 1 2
4 3 5
6 4 2
6 7 1
6 7 4
4 5 9
7 6 5 4 3 2 1
输出:
19
36
14
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |