Restaurants

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

문제

Everybody is very happy to go back outside and to restaurants in Paris. However, for a while yet the restaurants have a very limited number of seats. We want to ensure that both restaurants can receive as many people as possible, and that customers go in their preferred seats.

We have NN customers, numbered from 11 to NN, and MM restaurants, numbered from 11 to MM. Each customer makes reservation in a subset of the restaurants, and give their list of reservations ordered by preference.  Each restaurant ranks the reservations it received by some order of preference -- for instance, the restaurant might wish customers who have signed up first to be ranked higher. Each restaurant ii also has a capacity c_ic\_i, i.e. the maximal number of customers it can support.

Your task is to find an allocation of some of the customers in restaurants such that the following conditions are fulfilled:

  1. No restaurant places more customers than their capacity.

  2. Each customer is given a table in at most one restaurant.

  3. There is no restaurant rr and customer cc having made a reservation for rr, such that:

    • cc has not been given a table or prefers rr to the restaurant he was given a table in, and 
    • rr has some seats left or rr is full but prefers cc to at least one of the customers assigned to it.

Other remarks to note:

  • Every customer has made at least one reservation.
  • Restaurants only rank the customers having expressed a reservation for them. It is possible that a restaurant has no customers wishing to make a reservation.

입력

The first line contains NN and MM.

The MM following lines describe capacities with the ii-th line containing an integer c_ic\_i, the capacity of restaurant ii.

NN lines follow. The ii-th line describes the list of reservations for customer ii, sorted by preferences: the line contains a list of distinct space-separated integers (between 1 and MM), from most to least preferred.

MM lines follow. The ii-th line describes the sorted preferences of restaurant ii. This line contains either the number 0 when no customer made a reservation to restaurant ii or it contains a list of space-separated distinct integers, the list of customers who made a reservation to restaurant ii ordered from most to least preferred by the restaurant.

출력

The output described the set of customers which have a table in one possible allocation (according to the rules above). The set is given with one customer per line, sorted ascending by id.

제한

  • 1N50,0001\leq N \leq 50\\,000
  • 1M10,0001\leq M \leq 10\\,000
  • total number of reservation options is at most 1,000,0001\\,000\\,000.
  • 1c_iN1\leq c\_i \leq N