310916: CF1909E. Multiple Lamps
Description
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.
InputEach 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$.
OutputFor 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.
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 5Output
-1 4 3 5 1 2 3 8 9 10 1 5Note
In the first test case, you need to turn at most $\lfloor 4/5 \rfloor$ lamps on, which means that no lamp can be turned on. You can show that no choice of at least one button turns $0$ lamps on.
In the second test case, you can press buttons $3$, $5$, $1$, $2$.
- Initially, all the lamps are off;
- after pressing button $3$, the lamps whose index is a multiple of $3$ (i.e., $3$) are toggled, so lamp $3$ is turned on;
- after pressing button $5$, the lamps whose index is a multiple of $5$ (i.e., $5$) are toggled, so lamps $3$, $5$ are turned on;
- after pressing button $1$, the lamps whose index is a multiple of $1$ (i.e., $1$, $2$, $3$, $4$, $5$) are toggled, so lamps $1$, $2$, $4$ are turned on;
- after pressing button $2$, the lamps whose index is a multiple of $2$ (i.e., $2$, $4$) are toggled, so lamp $1$ is turned on.
This is valid because
- you pressed at least one button;
- you pressed all the buttons at most once;
- you pressed button $u_2 = 5$, which means that you had to also press button $v_2 = 1$: in fact, button $1$ has been pressed;
- at the end, only lamp $1$ is on.
In the third test case, pressing the buttons $8$, $9$, $10$ turns only the lamps $8$, $9$, $10$ on.
Output
你拥有n盏灯,编号从1到n。初始时,所有的灯都是关闭的。
你还有n个按钮。第i个按钮会切换所有索引是i的倍数的灯。当一盏灯被切换时,如果它是关闭的,它会被打开;如果它是打开的,它会被关闭。
你必须按照以下规则按下一些按钮:
- 你必须至少按下一个按钮。
- 你不能多次按下同一个按钮。
- 你会得到m对(u_i, v_i)。如果你按下按钮u_i,你也必须按下按钮v_i(在任何时刻,不一定要在按下按钮u_i之后)。注意,如果你按下按钮v_i,你不需要按下按钮u_i。
你不想浪费太多电力。找到一种按按钮的方式,使得最后最多有⌊n/5⌋盏灯是打开的,或者如果不可能的话,打印-1。
输入输出数据格式:
输入:
- 第一行包含一个整数t(1≤t≤10^4),表示测试用例的数量。
- 每个测试用例的第一行包含两个整数n和m(1≤n≤2×10^5,0≤m≤2×10^5),分别表示灯的数量和灯对的数量。
- 接下来的m行,每行包含两个整数u_i和v_i(1≤u_i,v_i≤n,u_i≠v_i)。如果你按下按钮u_i,你也必须按下按钮v_i。保证(u_i, v_i)对是唯一的。
- 保证所有测试用例的n和m之和不超过2×10^5。
输出:
- 对于每个测试用例:
- 如果没有选择按钮可以使最后最多有⌊n/5⌋盏灯打开,输出一行包含-1。
- 否则,输出两行。第一行包含一个整数k(1≤k≤n),表示按下的按钮数量。第二行包含k个整数b_1, b_2, …, b_k(1≤b_i≤n),表示按下的按钮的索引(顺序不限)。b_i必须是不同的,并且最后最多有⌊n/5⌋盏灯打开。题目大意: 你拥有n盏灯,编号从1到n。初始时,所有的灯都是关闭的。 你还有n个按钮。第i个按钮会切换所有索引是i的倍数的灯。当一盏灯被切换时,如果它是关闭的,它会被打开;如果它是打开的,它会被关闭。 你必须按照以下规则按下一些按钮: - 你必须至少按下一个按钮。 - 你不能多次按下同一个按钮。 - 你会得到m对(u_i, v_i)。如果你按下按钮u_i,你也必须按下按钮v_i(在任何时刻,不一定要在按下按钮u_i之后)。注意,如果你按下按钮v_i,你不需要按下按钮u_i。 你不想浪费太多电力。找到一种按按钮的方式,使得最后最多有⌊n/5⌋盏灯是打开的,或者如果不可能的话,打印-1。 输入输出数据格式: 输入: - 第一行包含一个整数t(1≤t≤10^4),表示测试用例的数量。 - 每个测试用例的第一行包含两个整数n和m(1≤n≤2×10^5,0≤m≤2×10^5),分别表示灯的数量和灯对的数量。 - 接下来的m行,每行包含两个整数u_i和v_i(1≤u_i,v_i≤n,u_i≠v_i)。如果你按下按钮u_i,你也必须按下按钮v_i。保证(u_i, v_i)对是唯一的。 - 保证所有测试用例的n和m之和不超过2×10^5。 输出: - 对于每个测试用例: - 如果没有选择按钮可以使最后最多有⌊n/5⌋盏灯打开,输出一行包含-1。 - 否则,输出两行。第一行包含一个整数k(1≤k≤n),表示按下的按钮数量。第二行包含k个整数b_1, b_2, …, b_k(1≤b_i≤n),表示按下的按钮的索引(顺序不限)。b_i必须是不同的,并且最后最多有⌊n/5⌋盏灯打开。