Supporting everyone

면접 대비

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

요약
N개 국가마다 이름 핀을 사거나(비용 1) 국기의 모든 색을 크레용으로 칠해야 하며, 서로 다른 크레용 하나에 1씩 들 때 전체 최소 비용을 구한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 비트 연산, 그리디, 구현
정답자
아직 제출이 없습니다

문제

Alice is attending a sport event with many national teams and one thing is important to her: supporting every country.

There are NN countries represented and she has two ways to support a country: either have the flag drawn on her or have a pin with the name of the country. Alice has a list containing, for each country, the colours needed to make its flag. A total of MM colours that may appear across all flags and, in Alice’s list, each colour is conveniently represented as an integer between 11 and MM.

Each crayon and pin cost 11, but her budget is tight. . . Can you help her find the minimum she can spend to support everyone?

입력

The first line contains the two space-separated numbers NN and MM. Then follow 2N2N lines, grouped in pairs; the (2i−1)(2i - 1)th and 2i2ith lines represent the iith country. More precisely, the (2i−1)(2i - 1)th line contains a single integer k_ik\_i: the number of colours in the flag of the iith country. Then, the 2i2ith line contains k_ik\_i space-separated numbers c_i,1,c_i,2,…,c_i,k_ic\_{i,1}, c\_{i,2}, \dots , c\_{i,k\_i}; these are the colours in the flag of the iith country.

출력

The output should contain a single line, consisting of a single number: the minimum amount Alice can spend on crayons and pins to represent every country.

제한

  • 1≤N≤1,0001 \le N \le 1\\, 000
  • 1≤M≤1001 \le M \le 100
  • 1≤k_i≤M1 \le k\_i \le M for all i≤Ni \le N
  • 1≤c_i,j≤M1 \le c\_{i,j} \le M for all i≤Ni \le N and j≤k_ij \le k\_i
  • for all i≤Ni \le N, the MM colour numbers c_i,jc\_{i,j} are pairwise distinct.

예제2

  1. 예제 1

    입력
    7 6
    3
    1 4 5
    3
    1 4 5
    3
    1 4 5
    3
    3 4 5
    3
    3 4 5
    3
    3 4 5
    3
    2 5 6
    
    예상 출력
    5
    
  2. 예제 2

    입력
    8 12
    2
    7 9
    12
    1 2 3 4 5 6 7 8 9 10 11 12
    2
    7 9
    2
    7 9
    3
    3 4 11
    2
    7 9
    2
    7 9
    2
    7 9
    
    예상 출력
    4