最短路专题2 | CodeForces 449B - SPFA算法

本文介绍了如何使用SPFA算法解决CodeForces中关于最短路径的问题,总统Jzzhu希望关闭一些铁路线路但保持所有城市到首都的最短路径不变。文章详细讲解了SPFA算法的思路、优化策略,并提供了C++源代码示例。此外,还讨论了如何用Dijkstra算法解决相同问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最短路专题2 | CodeForces 449B - SPFA算法

B. Jzzhu and Cities

Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city uiu_iui to viv_ivi (and vise versa) using the iii-th road, the length of this road is xix_ixi. Finally, there are k train routes in the country. One can use the iii-th train route to go from capital of the country to city sis_isi (and vise versa), the length of this route is yiy_iyi.
J是A国的总统,这个国家有n个城市。1是首都,有m条公路连接这些城市。然后,有k个火车线。城市sis_isi到首都1的距离是yiy_iyi

Jzzhu doesn’t want to waste the money of the country, so he is going to close some of the train routes. Please tell Jzzhu the maximum number of the train routes which can be closed under the following condition: the length of the shortest path from every city to the capital mustn’t change.
J不想浪费钱,删除部分铁路,但是每个城市到达首都的最短路径不能被修改,也就是说,只有最短路径不经过这个铁路时,才可以删除。

Input

The first line contains three integers n, m, k(2 ≤ n ≤ 105;1 ≤ m ≤ 3⋅105;1 ≤ k ≤ 105)n, m, k (2 ≤ n ≤ 105; 1 ≤ m ≤ 3·105; 1 ≤ k ≤ 105)n,m,k(2n105;1m

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值