#P7681. [COCI 2008/2009 #5] LUBENICA

[COCI 2008/2009 #5] LUBENICA

Description

There are nn children in a class. During lessons, they do not listen carefully and instead play a watermelon-throwing game on the Facebook social website.

In the first lesson, Goran throws one watermelon to each of his friends. In the following lessons, the children act as follows:

  • If a person was hit by an odd number of watermelons in the previous lesson, then in this lesson they will throw one watermelon to each of their friends.
  • If a person was hit by an even number (including 00) of watermelons in the previous lesson, then in this lesson they will throw two watermelons to each of their friends.

The children are numbered from 11 to nn, and Goran's number is 11.

Now, given the number of children nn and all friendship relations among them, find the total number of watermelons thrown after hh lessons.

Input Format

The input has n+1n+1 lines.

The first line contains two integers n,hn, h, representing the number of children and the number of lessons.
Then follow nn lines, each containing nn integers (without spaces), forming a matrix. The ii-th line describes the friendships of the ii-th child. Specifically, if the jj-th element in line ii is 11, then child ii and child jj are friends; otherwise they are not.

The input matrix is symmetric (that is, if AA is a friend of BB, then BB is also a friend of AA), and it is guaranteed that no child is a friend of themselves.

Output Format

Output only one line with an integer, representing the total number of watermelons thrown after hh lessons.

4 1
0110
1001
1001
0110
2
4 2
0110
1001
1001
0110
14
5 3
01000
10110
01000
01001
00010 
26

Hint

[Explanation for Samples 1/2]

For Sample 1/21/2, first, in the first lesson, Goran throws one watermelon to children 22 and 33, and no other child throws any watermelons. Therefore, the answer for Sample 11 is 22.
In the second lesson, children 22 and 33 each throw one watermelon to children 11 and 44. Meanwhile, since children 11 and 44 were not hit by any watermelons in the previous lesson, they each throw 22 watermelons to children 22 and 33. Therefore, a total of 2×2×1+2×2×2=122\times 2\times 1+2\times 2\times 2=12 watermelons are thrown in the second lesson.

Thus, in the first two lessons, a total of 2+12=142+12=14 watermelons are thrown, which is the answer for Sample 22.

[Constraints]

For 50%50\% of the testdata, h1000h\leqslant 1000.
For all testdata, 1n201\leqslant n\leqslant 20, 1h1091\leqslant h\leqslant 10^9.

[Source]

This problem comes from COCI 2008-2009 CONTEST 5 T4 LUBENICA, and follows the original testdata settings, with a full score of 100100.

Translated and organized by Eason_AC.

Translated by ChatGPT 5