방향 그래프의 간선이 m일에 걸쳐 뒤집힐 때, 매일 변경이 끝난 뒤 서로 도달 가능한 두 정점 쌍의 개수를 구한다.
어려움8그래프동적 계획법비트 연산아직 제출이 없습니다시간 제한1초메모리 제한512 MBEvery time you come across a problem you've never seen before, haven't you thought of something that is familiar to you? If so, you might think of something else, then more and more things will come to your mind. This is what is called a logical chain. Lu Xun's work also described this interesting phenomenon.
Assume there are n concepts, labeled by 1, 2, …, n. Little Q's mind can be expressed by a n×n binary matrix g. If he can think of concept j when he comes across concept i, then g_i,j is 1, otherwise it is 0. For two different concepts u and v, if u can lead to v directly or indirectly and v can also lead to u directly or indirectly, then the pair (u,v) is called a looping pair.
Little Q's mind changes all the time. On i-th day, a total of k_i positions (u,v) in matrix g are flipped (0s become 1s and 1s become 0s). Your task is to write a program to find the number of looping pairs each day after all changes on that day.
When counting, pairs (u,v) and (v,u) should be considered the same.
The first line of the input contains two integers n and m, the number of concepts and the number of days (1≤n≤250, 1≤m≤25,000).
In the next n lines, line i contains n integers g_i,1, g_i,2, …, g_i,n (0≤g_i,j≤1, g_i,i=0). Together, these lines define the matrix g.
Each of the next m parts describes a single day and starts with a line with a single integer k_i, the number of changes which happened on day i (1≤k_i≤10). Each of the next k_i lines contains two integers u and v denoting a changed position in g (1≤u,v≤n, u=v).
It is guaranteed that each position will be changed at most once per day.
For each day, print a single line containing a single integer: the number of looping pairs after all changes of that day.