RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 ICPC00120

L. Restaurants

설명

3

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 \(N\) customers, numbered from \(1\) to \(N\), and \(M\) restaurants, numbered from \(1\) to \(M\).

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 \(i\) also has a capacity \(c_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:
- No restaurant places more customers than their capacity.
- Each customer is given a table in at most one restaurant.
- There is no other possible allocation of a customer to a restaurant so that both sides prefer it to the current allocation.
- There is no restaurant \(r\) and customer \(c\) having made a reservation for \(r\), such that:
- \(c\) has not been given a table or prefers \(r\) to the restaurant he was given a table in, and
- \(r\) has some seats left or \(r\) is full but prefers \(c\) 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 \(N\) and \(M\).

The \(M\) following lines describe capacities with the \(i\)-th line containing an integer \(c_i\), the capacity of restaurant \(i\).

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

\(M\) lines follow. The \(i\)-th line describes the sorted preferences of restaurant \(i\). This line contains either the number 0 when no customer made a reservation to restaurant \(i\) or it contains a list of space-separated distinct integers, the list of customers who made a reservation to restaurant \(i\) 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.

예제 1
입력
4 4
2
2
2
1
2
2 3
2 1 3
1 2 4 3
3 4
3 2 4 1
3 4 2
4
출력
2
3
4
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC SWERC 2020

평가 및 의견

L. Restaurants

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

L. Restaurants

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8