欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1081D.Maximum Distance
Maximum Distance
CF1081D · Maximum Distance
- 难度:1800
- 标签:dsu、graphs、shortest paths、sortings
- 链接:https://codeforces.com/problemset/problem/1081/D
- 时间限制:1 second 内存限制:256 megabytes
- 出现位置:Day12-Kruskal-离线排序-路径贡献
英文原题面
Statement
Chouti was tired of the tedious homework, so he opened up an old programming problem he created years ago. You are given a connected undirected graph with vertices and weighted edges. There are special vertices: . Let's define the cost of the path as the maximum weight of the edges in it. And the distance between two vertexes as the minimum cost of the paths connecting them. For each special vertex, find another special vertex which is farthest from it (in terms of the previous paragraph, i.e. the corresponding distance is maximum possible) and output the distance between them. The original constraints are really small so he thought the problem was boring. Now, he raises the constraints and hopes you can solve it for him.
Input
The first line contains three integers , and (, ) — the number of vertices, the number of edges and the number of special vertices. The second line contains distinct integers (). Each of the following lines contains three integers , and (), denoting there is an edge between and of weight . The given graph is undirected, so an edge can be used in the both directions. The graph may have multiple edges and self-loops. It is guaranteed, that the graph is connected.
Output
The first and only line should contain integers. The -th integer is the distance between and the farthest special vertex from it.
样例
样例 1
输入:
2 3 2
2 1
1 2 3
1 2 2
2 2 1
输出:
2 2
样例 2
输入:
4 5 3
1 2 3
1 2 5
4 2 1
2 3 2
1 4 4
1 3 3
输出:
3 3 3
样例解释(英文原文)
In the first example, the distance between vertex and equals to because one can walk through the edge of weight connecting them. So the distance to the farthest node for both and equals to . In the second example, one can find that distance between and , distance between and are both and the distance between and is . The graph may have multiple edges between and self-loops, as in the first example.
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |