codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1176E.md (2526B)


      1 Source: https://codeforces.com/problemset/problem/1176/E
      2 
      3 E. Cover it!
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You are given an undirected unweighted connected graph consisting of $n$ vertices and $m$ edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.
     22 
     23 Your task is to choose at most $\lfloor\frac{n}{2}\rfloor$ vertices in this graph so each unchosen vertex is adjacent (in other words, connected by an edge) to at least one of chosen vertices.
     24 
     25 It is guaranteed that the answer exists. If there are multiple answers, you can print any.
     26 
     27 You will be given multiple independent queries to answer.
     28 
     29 Input
     30 
     31 The first line contains a single integer $t$ ($1 \le t \le 2 \cdot 10^5$) — the number of queries.
     32 
     33 Then $t$ queries follow.
     34 
     35 The first line of each query contains two integers $n$ and $m$ ($2 \le n \le 2 \cdot 10^5$, $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.
     36 
     37 The following $m$ lines denote edges: edge $i$ is represented by a pair of integers $v_i$, $u_i$ ($1 \le v_i, u_i \le n$, $u_i \ne v_i$), which are the indices of vertices connected by the edge.
     38 
     39 There are no self-loops or multiple edges in the given graph, i. e. for each pair ($v_i, u_i$) there are no other pairs ($v_i, u_i$) or ($u_i, v_i$) in the list of edges, and for each pair ($v_i, u_i$) the condition $v_i \ne u_i$ is satisfied. It is guaranteed that the given graph is connected.
     40 
     41 It is guaranteed that $\sum m \le 2 \cdot 10^5$ over all queries.
     42 
     43 Output
     44 
     45 For each query print two lines.
     46 
     47 In the first line print $k$ ($1 \le \lfloor\frac{n}{2}\rfloor$) — the number of chosen vertices.
     48 
     49 In the second line print $k$ distinct integers $c_1, c_2, \dots, c_k$ in any order, where $c_i$ is the index of the $i$-th chosen vertex.
     50 
     51 It is guaranteed that the answer exists. If there are multiple answers, you can print any.
     52 
     53 Example
     54 
     55 Input
     56 
     57 ```
     58 2
     59 4 6
     60 1 2
     61 1 3
     62 1 4
     63 2 3
     64 2 4
     65 3 4
     66 6 8
     67 2 5
     68 5 4
     69 4 3
     70 4 1
     71 1 3
     72 2 3
     73 2 6
     74 5 6
     75 ```
     76 
     77 Output
     78 
     79 ```
     80 2
     81 1 3
     82 3
     83 4 3 6
     84 ```
     85 
     86 Note
     87 
     88 In the first query any vertex or any pair of vertices will suffice.
     89 
     90  ![](https://espresso.codeforces.com/21a41ff2a5c3b5cbdf9862443dce8b7be9228b4d.png) 
     91 
     92 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.
     93 
     94  ![](https://espresso.codeforces.com/0cf2a7649e6c2874e35aa8bc118dc06c0d99f72f.png)