AtCoder Beginner Contest 243
比赛链接
AtCoder Beginner Contest 243
E - Edge Deletion
Problem Statement
You are given a simple connected undirected graph with vertices and edges.
Edge connects Vertex and Vertex , and has a length of .
Let us delete some number of edges while satisfying the conditions below. Find the maximum number of edges that can be deleted.
- The graph is still connected after the deletion.
- For every pair of vertices , the distance between and remains the same before and after the deletion.
Notes
A simple connected undirected graph is a graph that is simple and connected and has undirected edges.
A graph is simple when it has no self-loops and no multi-edges.
A graph is connected when, for every pair of two vertices and is reachable from by traversing edges.
The distance between Vertex and Vertex is the length of a shortest path between and .
Constraints
- if .
- The given graph is connected.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
Sample Output 1
The distance between each pair of vertices before the deletion is as follows.
The distance between Vertex and Vertex is .
The distance between Vertex and Vertex is .
The distance between Vertex and Vertex is .
Deleting Edge does not affect the distance between any pair of vertices. It is impossible to delete two or more edges while satisfying the condition, so the answer is .
Sample Input 2
Sample Output 2
No edge can be deleted.
Sample Input 3
Sample Output 3
解题思路
floyd
先用floyd
求出每对点之间的最短路,再遍历每一条边,如果存在 到 的路径中经过其他点的路径不大于两点之间的距离,由于距离非负,即该路径跟两点间的距离没有关系,且这条路径比这条边更优,则这条边可以删去
- 时间复杂度:
代码
__EOF__

本文链接:https://www.cnblogs.com/zyyun/p/15998976.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是博主的最大动力!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!