Greedy Bipartite Matching

아직 제출이 없습니다시간 제한10초메모리 제한1024 MB

문제

Consider a bipartite weighted graph with 2n2 n vertices: nn in the left part and nn in the right part. The vertices in each part are numbered from 11 to nn. A matching is called greedy if it has the maximal number of edges of weight 11 among all matchings, the maximal number of edges of weight 22 among all matchings that maximize the number of edges of weight 11, etc.

Your task is to find the size (number of edges) of greedy matching in a dynamically growing graph.

입력

The first line of the input contains two non-negative integers nn and qq (n105n \leq 10^5, q103q \leq 10^3): the number of vertices in each part and the number of different weights of the edges.

Then, the input consists of qq blocks. The ii-th block starts with a non-negative integer m_im\_i: the number of edges of weight ii. Each of the next m_im\_i lines contains two integers xx and yy (1x,yn1 \leq x, y \leq n), which add an edge between vertex xx of the left part and vertex yy of the right part. It is guaranteed that _im_i2105\sum\_i m\_i \leq 2 \cdot 10^5.

Note that there may be multiple edges between two vertices.

출력

You have to output qq integers on a single line: answers for the problem for weights at most 11, weights at most 22, \ldots, weights at most qq.