CF1909E.Multiple Lamps

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Kid2Will - Fire Aura

⠀

You have nn lamps, numbered from 11 to nn. Initially, all the lamps are turned off.

You also have nn buttons. The ii-th button toggles all the lamps whose index is a multiple of ii. 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 mm pairs (ui,vi)(u_i, v_i). If you press the button uiu_i, you also have to press the button viv_i (at any moment, not necessarily after pressing the button uiu_i). Note that, if you press the button viv_i, you don't need to press the button uiu_i.

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

Kid2Will - Fire Aura

⠀

你有 nn 盏灯,编号从 11 到 nn。初始时,所有灯均处于关闭状态。

你还有 nn 个按钮。第 ii 个按钮会切换所有下标为 ii 的倍数的灯的状态:若灯当前为关闭,则变为开启;若为开启,则变为关闭。

你需要按照以下规则按下若干按钮:

  • 至少要按下其中一个按钮;
  • 同一个按钮不能被多次按下;
  • 给定 mm 对 (ui,vi)(u_i, v_i)。若你按下了按钮 uiu_i,则你也必须按下按钮 viv_i(可在任意时刻按下,不一定要在按下 uiu_i 之后立即按下)。注意:若你按下了按钮 viv_i,则不一定需要按下按钮 uiu_i。

你不希望消耗过多电能。请找出一种按钮按下方案,使得最终最多有 ⌊n/5⌋\lfloor n/5 \rfloor 盏灯处于开启状态;若不存在这样的方案,请输出 −1-1。

输入格式

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

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

Each of the next mm lines contains two integers uiu_i, viv_i (1≤ui,vi≤n1 \leq u_i, v_i \leq n, ui≠viu_i \neq v_i). If you press the button uiu_i, you also have to press the button viv_i. It is guaranteed that the pairs (ui,vi)(u_i, v_i) are distinct.

It is guaranteed that the sum of nn and the sum of mm over all test cases do not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5,0≤m≤2⋅1050 \leq m \leq 2 \cdot 10^5),分别表示灯的数量和配对数量。

接下来的 mm 行中,每行包含两个整数 uiu_i、viv_i(1≤ui,vi≤n1 \leq u_i, v_i \leq n,ui≠viu_i \neq v_i):若按下按钮 uiu_i,则也必须按下按钮 viv_i。保证所有配对 (ui,vi)(u_i, v_i) 互不相同。

保证所有测试用例的 nn 之和以及 mm 之和均不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case:

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

对于每个测试用例:

  • 如果不存在一种按钮选择方案,使得最终亮着的灯的数量不超过 ⌊n/5⌋\lfloor n/5 \rfloor,则输出一行,包含单个整数 −1-1。
  • 否则,输出两行。第一行应包含一个整数 kk(1≤k≤n1 \le k \le n)—— 按下的按钮数量;第二行应包含 kk 个整数 b1,b2,…,bkb_1, b_2, \dots, b_k(1≤bi≤n1 \le b_i \le n)—— 按下的按钮的编号(顺序任意)。这些 bib_i 必须互不相同,且最终亮着的灯的数量不得超过 ⌊n/5⌋\lfloor n/5 \rfloor。

输入输出样例

  • 输入#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

说明/提示

In the first test case, you need to turn at most ⌊4/5⌋\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 00 lamps on.

In the second test case, you can press buttons 33, 55, 11, 22.

  • Initially, all the lamps are off;
  • after pressing button 33, the lamps whose index is a multiple of 33 (i.e., 33) are toggled, so lamp 33 is turned on;
  • after pressing button 55, the lamps whose index is a multiple of 55 (i.e., 55) are toggled, so lamps 33, 55 are turned on;
  • after pressing button 11, the lamps whose index is a multiple of 11 (i.e., 11, 22, 33, 44, 55) are toggled, so lamps 11, 22, 44 are turned on;
  • after pressing button 22, the lamps whose index is a multiple of 22 (i.e., 22, 44) are toggled, so lamp 11 is turned on.

This is valid because

  • you pressed at least one button;
  • you pressed all the buttons at most once;
  • you pressed button u2=5u_2 = 5, which means that you had to also press button v2=1v_2 = 1: in fact, button 11 has been pressed;
  • at the end, only lamp 11 is on.

In the third test case, pressing the buttons 88, 99, 1010 turns only the lamps 88, 99, 1010 on.

在第一个测试用例中,你最多需要打开 ⌊4/5⌋\lfloor 4/5 \rfloor 盏灯,即不允许打开任何一盏灯。你可以验证:无论选择至少一个按钮进行按压,都无法使恰好 00 盏灯被打开。

在第二个测试用例中,你可以依次按压按钮 33、55、11、22。

  • 初始时,所有灯均处于关闭状态;
  • 按压按钮 33 后,所有下标为 33 的倍数的灯(即灯 33)被翻转,因此灯 33 被打开;
  • 按压按钮 55 后,所有下标为 55 的倍数的灯(即灯 55)被翻转,因此灯 33 和灯 55 处于开启状态;
  • 按压按钮 11 后,所有下标为 11 的倍数的灯(即灯 11、22、33、44、55)被翻转,因此灯 11、22、44 被打开;
  • 按压按钮 22 后,所有下标为 22 的倍数的灯(即灯 22、44)被翻转,因此最终仅有灯 11 处于开启状态。

该方案是合法的,因为:

  • 你按压了至少一个按钮;
  • 每个按钮至多被按压一次;
  • 你按压了按钮 u2=5u_2 = 5,这意味着你必须也按压按钮 v2=1v_2 = 1;事实上,按钮 11 确实已被按压;
  • 最终,仅灯 11 处于开启状态。

在第三个测试用例中,按压按钮 88、99、1010 后,仅有灯 88、99、1010 被打开。

输入解题思路,AI测评打分。不知道怎么写?

首页