#P7681. [COCI 2008/2009 #5] LUBENICA
[COCI 2008/2009 #5] LUBENICA
Description
There are 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 ) 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 to , and Goran's number is .
Now, given the number of children and all friendship relations among them, find the total number of watermelons thrown after lessons.
Input Format
The input has lines.
The first line contains two integers , representing the number of children and the number of lessons.
Then follow lines, each containing integers (without spaces), forming a matrix. The -th line describes the friendships of the -th child. Specifically, if the -th element in line is , then child and child are friends; otherwise they are not.
The input matrix is symmetric (that is, if is a friend of , then is also a friend of ), 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 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 , first, in the first lesson, Goran throws one watermelon to children and , and no other child throws any watermelons. Therefore, the answer for Sample is .
In the second lesson, children and each throw one watermelon to children and . Meanwhile, since children and were not hit by any watermelons in the previous lesson, they each throw watermelons to children and . Therefore, a total of watermelons are thrown in the second lesson.
Thus, in the first two lessons, a total of watermelons are thrown, which is the answer for Sample .
[Constraints]
For of the testdata, .
For all testdata, , .
[Source]
This problem comes from COCI 2008-2009 CONTEST 5 T4 LUBENICA, and follows the original testdata settings, with a full score of .
Translated and organized by Eason_AC.
Translated by ChatGPT 5
京公网安备 11011102002149号