Greedy Bipartite Matching
Time limit10sMemory limit1024 MB
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 vertices: in the left part and in the right part. The vertices in each part are numbered from to . A matching is called greedy if it has the maximal number of edges of weight among all matchings, the maximal number of edges of weight among all matchings that maximize the number of edges of weight , 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 and (, ): the number of vertices in each part and the number of different edge weights.
Then the input consists of blocks. The -th block starts with a non-negative integer , the number of edges of weight . Each of the next lines contains two integers and (), which add an edge between vertex of the left part and vertex of the right part. It is guaranteed that .
There may be multiple edges between the same two vertices.
Output
Output integers on a single line: the answers for weights at most , weights at most , ..., weights at most .