CF1270G.Subset with Zero Sum
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n integers a1,a2,…,an , such that for each 1≤i≤n holds i−n≤ai≤i−1 .
Find some nonempty subset of these integers, whose sum is equal to 0 . It can be shown that such a subset exists under given constraints. If there are several possible subsets with zero-sum, you can find any of them.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤106 ). The description of the test cases follows.
The first line of each test case contains a single integer n ( 1≤n≤106 ).
The second line of each test case contains n integers a1,a2,…,an ( i−n≤ai≤i−1 ).
It is guaranteed that the sum of n over all test cases does not exceed 106 .
输出格式
For each test case, output two lines.
In the first line, output s ( 1≤s≤n ) — the number of elements in your subset.
In the second line, output s integers i1,i2,…,is ( 1≤ik≤n ). All integers have to be pairwise different, and ai1+ai2+⋯+ais has to be equal to 0 . If there are several possible subsets with zero-sum, you can find any of them.
输入输出样例
输入#1
2 5 0 1 2 3 4 4 -3 1 1 1
输出#1
1 1 4 1 4 3 2
说明/提示
In the first example, we get sum is a1=0 .
In the second example, we get sum is a1+a4+a3+a2=0 .