Supporting everyone
면접 대비시간 제한0.25초메모리 제한1024 MB
N개 국가마다 이름 핀을 사거나(비용 1) 국기의 모든 색을 크레용으로 칠해야 하며, 서로 다른 크레용 하나에 1씩 들 때 전체 최소 비용을 구한다.
문제
Alice is attending a sport event with many national teams and one thing is important to her: supporting every country.
There are 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 colours that may appear across all flags and, in Alice’s list, each colour is conveniently represented as an integer between and .
Each crayon and pin cost , 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 and . Then follow lines, grouped in pairs; the th and th lines represent the th country. More precisely, the th line contains a single integer : the number of colours in the flag of the th country. Then, the th line contains space-separated numbers ; these are the colours in the flag of the th 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.
제한
- for all
- for all and
- for all , the colour numbers are pairwise distinct.