欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
5093.Cover it!
Cover it!
CF1176E · Cover it!
- 难度:1700
- 标签:dfs and similar、dsu、graphs、shortest paths、trees
- 链接:https://codeforces.com/problemset/problem/1176/E
- 时间限制:2 seconds 内存限制:256 megabytes
- 出现位置:Day12-Kruskal-离线排序-路径贡献
英文原题面
Statement
You are given an undirected unweighted connected graph consisting of vertices and edges. It is guaranteed that there are no self-loops or multiple edges in the given graph. Your task is to choose at most vertices in this graph so each unchosen vertex is adjacent (in other words, connected by an edge) to at least one of chosen vertices. It is guaranteed that the answer exists. If there are multiple answers, you can print any. You will be given multiple independent queries to answer.
Input
The first line contains a single integer () — the number of queries. Then queries follow. The first line of each query contains two integers and (, $n - 1 \le m \le min(2 \cdot 10^5, \frac{n(n-1)}{2})$) — the number of vertices and the number of edges, respectively. The following lines denote edges: edge is represented by a pair of integers , (, ), which are the indices of vertices connected by the edge. There are no self-loops or multiple edges in the given graph, i. e. for each pair () there are no other pairs () or () in the list of edges, and for each pair () the condition is satisfied. It is guaranteed that the given graph is connected. It is guaranteed that over all queries.
Output
For each query print two lines. In the first line print () — the number of chosen vertices. In the second line print distinct integers in any order, where is the index of the -th chosen vertex. It is guaranteed that the answer exists. If there are multiple answers, you can print any.
样例
样例 1
输入:
2
4 6
1 2
1 3
1 4
2 3
2 4
3 4
6 8
2 5
5 4
4 3
4 1
1 3
2 3
2 6
5 6
输出:
2
1 3
3
4 3 6
样例解释(英文原文)
In the first query any vertex or any pair of vertices will suffice.
Note that you don't have to minimize the number of chosen vertices. In the second query two vertices can be enough (vertices and ) but three is also ok.
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |