Under construction

Still being built. Things may change

Greedy Bipartite Matching

Time limit10sMemory limit1024 MB

Summary
For each q, find the size of the greedy matching that uses edges of weight at most q in a bipartite graph whose edges arrive in weight layers.
Level

Hard9 of 10

Topics
Graph, Greedy, Divide and conquer
Solved
No attempts yet

Problem

Consider a bipartite weighted graph with 2n2n 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, and so on.

The goal is to find the size (number of edges) of a greedy matching in a graph that keeps growing.

Input

The first line contains two non-negative integers nn and qq (n≤105n \leq 10^5, q≤103q \leq 10^3): the number of vertices in each part and the number of different edge weights.

Then the input consists of qq blocks. The ii-th block starts with a non-negative integer mim_i, the number of edges of weight ii. Each of the next mim_i lines contains two integers xx and yy (1≤x,y≤n1 \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 ∑mi≤2⋅105\sum m_i \leq 2 \cdot 10^5.

There may be multiple edges between the same two vertices.

Output

Output qq integers on a single line: the answers for weights at most 11, weights at most 22, ..., weights at most qq.

Examples1

  1. Example 1

    Input
    3 4
    2
    1 1
    1 2
    2
    1 1
    2 2
    2
    1 3
    3 2
    1
    3 3
    
    Expected output
    1 2 2 3