-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths004_e00415.py
63 lines (38 loc) · 2.79 KB
/
s004_e00415.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 7 14:18:57 2022
@author: Luke
Prompt
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𝑙𝑓𝑙𝑜𝑜𝑟𝑓𝑟𝑎𝑐𝑛2𝑟𝑓𝑙𝑜𝑜𝑟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 𝑡 (1𝑙𝑒𝑡𝑙𝑒2𝑐𝑑𝑜𝑡105) — the number of queries.
Then 𝑡 queries follow.
The first line of each query contains two integers 𝑛 and 𝑚 (2𝑙𝑒𝑛𝑙𝑒2𝑐𝑑𝑜𝑡105,𝑛−1𝑙𝑒𝑚𝑙𝑒𝑚𝑖𝑛(2𝑐𝑑𝑜𝑡105,𝑓𝑟𝑎𝑐𝑛(𝑛−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 𝑣𝑖 , 𝑢𝑖 (1𝑙𝑒𝑣𝑖,𝑢𝑖𝑙𝑒𝑛,𝑢𝑖𝑛𝑒𝑣𝑖), 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𝑠𝑢𝑚𝑚𝑙𝑒2𝑐𝑑𝑜𝑡105over all queries.
-----Output-----
For each query print two lines.
In the first line print 𝑘 (1𝑙𝑒𝑙𝑓𝑙𝑜𝑜𝑟𝑓𝑟𝑎𝑐𝑛2𝑟𝑓𝑙𝑜𝑜𝑟) — the number of chosen vertices.
In the second line print 𝑘 distinct integers𝑐1,𝑐2,𝑑𝑜𝑡𝑠,𝑐𝑘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.
-----Example----- Input 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
Output 2 1 3 3 4 3 6
-----Note-----
In the first query any vertex or any pair of vertices will suffice.
[Image]
Note that you don't have to minimize the number of chosen vertices. In the second query two vertices can be enough (vertices 2 and 4 ) but three is also ok.
[Image]
"""
def main():
t = int(input())
for _ in range(t):
n, m = map(int, input().split())
edges = []
for _ in range(m):
edges.append(tuple(map(int, input().split())))
print(n // 2)
print(*range(1, n // 2 + 1))