아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Gift Giving

면접 대비

시간 제한1초메모리 제한1024 MB

요약
각 소가 원하는 선물 목록과 보유한 선물 목록이 주어질 때, 서로 다른 선물을 받아 만족하는 소의 최대 수를 구한다.
난이도

보통10점 중 6점

유형
그래프, BFS, 해시맵
정답자
아직 제출이 없습니다

문제

It's a holiday down at the farm. You've purchased gifts for the cows and now are trying to choose the perfect gift for each cow. Each cow has given you her wish list for gifts. Each cow will receive exactly one gift. A cow is pleased by her gift only if it appears on her wish list.

Your job is to determine the greatest number of cows that can be pleased given a certain set of gifts to give. The list of gifts might list a gift more than once if more than one was bought.

In this problem, each gift will be designated by an integer in the range 1..1000.

입력

  • Line 1: two integers: C, 1 ≤ C ≤ 100, the number of cows getting gifts G, C ≤ G ≤ 100, the number of gifts to give
  • Line 2: G single-space separated integers denoting gifts to give
  • Line 3..C+2: C lines specifying gifts cows want, each line like this: n w1 w2 ... wn where n is the number of gifts that cow wants and w0, w1, etc. are the gift numbers.

출력

A single line with an integer that tells how many cows can be satisfied by the list of gifts.

예제1

  1. 예제 1

    입력
    5 5
    35 35 483 622 801
    1 35
    1 35
    1 35
    3 483 622 801
    3 35 801 483
    
    예상 출력
    4