题库练习 Multiple Lamps
← 上一题 下一题 →

A16444 | Multiple Lamps

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

[Kid2Will - Fire Aura](https://soundcloud.com/xgp/kid2will-fire-aura)

⠀



You have $n$ lamps, numbered from $1$ to $n$ . Initially, all the lamps are turned off.

You also have $n$ buttons. The $i$ -th button toggles all the lamps whose index is a multiple of $i$ . When a lamp is toggled, if it was off it turns on, and if it was on it turns off.

You have to press some buttons according to the following rules.

- You have to press at least one button.
- You cannot press the same button multiple times.
- You are given $m$ pairs $(u_i, v_i)$ . If you press the button $u_i$ , you also have to press the button $v_i$ (at any moment, not necessarily after pressing the button $u_i$ ). Note that, if you press the button $v_i$ , you don't need to press the button $u_i$ .

You don't want to waste too much electricity. Find a way to press buttons such that at the end at most $\lfloor n/5 \rfloor$ lamps are on, or print $-1$ if it is impossible.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 10^4$ ). The description of the test cases follows.

The first line of each test case contains two integers $n$ and $m$ ( $1 \leq n \leq 2 \cdot 10^5$ , $0 \leq m \leq 2 \cdot 10^5$ ) — the number of lamps and the number of pairs, respectively.

Each of the next $m$ lines contains two integers $u_i$ , $v_i$ ( $1 \leq u_i, v_i \leq n$ , $u_i \neq v_i$ ). If you press the button $u_i$ , you also have to press the button $v_i$ . It is guaranteed that the pairs $(u_i, v_i)$ are distinct.

It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2 \cdot 10^5$ .

输出格式

For each test case:

- If there is no choice of buttons that makes at most $\lfloor n/5 \rfloor$ lamps on at the end, output a single line containing $-1$ .
- Otherwise, output two lines. The first line should contain an integer $k$ ( $1 \le k \le n$ ) — the number of pressed buttons. The second line should contain $k$ integers $b_1, b_2, \dots, b_k$ ( $1 \le b_i \le n$ ) — the indices of the pressed buttons (in any order). The $b_i$ must be distinct, and at the end at most $\lfloor n/5 \rfloor$ lamps must be turned on.

输入输出样例

输入 #1
4
4 0
5 2
4 1
5 1
15 9
7 8
8 9
9 10
10 9
11 1
12 2
13 3
14 4
15 5
5 4
1 2
2 3
3 4
4 5
输出 #1
-1
4
3 5 1 2
3
8 9 10
1
5
C++ 编辑器
输入
输出