Under construction

Still being built. Things may change

Finding Liars

Time limit3sMemory limit128 MB

Summary
Given a circular chain of accusations among truth-tellers and liars with at most t liars, identify people who must be liars in every consistent assignment.
Level

Medium6 of 10

Topics
Greedy, Simulation, Math
Solved
No attempts yet

Problem

There are n≥2n \ge 2 people labeled 1,2,…,n1, 2, \dots, n. Each person is either a truth-teller or a liar, and the total number of liars is at most tt (with t≤nt \le n).

Any person ii can test another person jj and report whether jj is a truth-teller or a liar. The outcome ai,ja_{i,j} is 11 if person ii reports that jj is a liar, and 00 if person ii reports that jj is a truth-teller. A report is reliable exactly when the tester ii is a truth-teller; if the tester ii is a liar, the report is unreliable and may take either value. The outcomes are summarized below.

tester iitested jjoutcome ai,ja_{i,j}
truth-tellertruth-teller00
truth-tellerliar11
liartruth-teller00 or 11
liarliar00 or 11

Testing is arranged in a circle: person 11 tests person 22, person 22 tests person 33, …\dots, person n−1n-1 tests person nn, and person nn tests person 11. From the outcomes, some people are guaranteed to be liars, while others may or may not be liars. Given nn, tt, and the outcomes, determine which people are definitely liars.

For example, let n=5n = 5, t=2t = 2, and let the outcomes (a1,2,a2,3,a3,4,a4,5,a5,1)(a_{1,2}, a_{2,3}, a_{3,4}, a_{4,5}, a_{5,1}) be (0,1,1,0,0)(0, 1, 1, 0, 0). Person 33 must be a liar: if person 33 were a truth-teller, then following the reports forces persons 11, 44, and 55 to be liars as well, giving at least three liars and contradicting t=2t = 2. So person 33 is a definite liar. However, both {3,4}\{3, 4\} and {3}\{3\} are possible liar sets, so person 44 cannot be pinned down as a definite liar.

You may assume the given outcomes come from some assignment that has at most tt liars.

Input

The first line contains the number of test cases TT. Each test case has two lines. The first line has two integers: nn (1≤n≤10001 \le n \le 1000), the number of people, and tt (0≤t≤n0 \le t \le n), the maximum number of liars. The second line has nn values, each 00 or 11, giving a1,2,a2,3,…,an−1,n,an,1a_{1,2}, a_{2,3}, \dots, a_{n-1,n}, a_{n,1} in this order.

Output

For each test case, print one line with two integers: the number of definite liars, and the smallest label among the definite liars. If there are no definite liars, print 00 as the second integer.

Examples3

  1. Example 1

    Input
    3
    5 2
    0 1 1 0 0
    7 2
    0 0 1 0 0 1 1
    9 8
    1 0 0 0 0 1 0 0 0
    
    Expected output
    1 3
    2 4
    0 0
    
  2. Example 2

    Input
    1
    4 2
    0 0 0 0
    
    Expected output
    0 0
    
  3. Example 3

    Input
    2
    1 0
    0
    1 1
    1
    
    Expected output
    0 0
    1 1