CF367D.Sereja and Sets

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Sereja has mm non-empty sets of integers A1,A2,...,AmA_{1},A_{2},...,A_{m} . What a lucky coincidence! The given sets are a partition of the set of all integers from 1 to nn . In other words, for any integer vv (1<=v<=n)(1<=v<=n) there is exactly one set AtA_{t} such that . Also Sereja has integer dd .

Sereja decided to choose some sets from the sets he has. Let's suppose that i1,i2,...,iki_{1},i_{2},...,i_{k} (1<=i_{1}<i_{2}<...<i_{k}<=m) are indexes of the chosen sets. Then let's define an array of integers bb , sorted in ascending order, as a union of the chosen sets, that is, . We'll represent the element with number jj in this array (in ascending order) as bjb_{j} . Sereja considers his choice of sets correct, if the following conditions are met:

b_{1}<=d; b_{i+1}-b_{i}<=d (1<=i<|b|); n-d+1<=b_{|b|}. Sereja wants to know what is the minimum number of sets (k)(k) that he can choose so that his choice will be correct. Help him with that.

输入格式

The first line contains integers nn , mm , dd (1<=d<=n<=105,1<=m<=20)(1<=d<=n<=10^{5},1<=m<=20) . The next mm lines contain sets. The first number in the ii -th line is sis_{i} (1<=si<=n)(1<=s_{i}<=n) . This number denotes the size of the ii -th set. Then the line contains sis_{i} distinct integers from 1 to nn — set AiA_{i} .

It is guaranteed that the sets form partition of all integers from 1 to nn .

输出格式

In a single line print the answer to the problem — the minimum value kk at the right choice.

输入输出样例

  • 输入#1

    3 2 2
    1 2
    2 1 3
    

    输出#1

    1
    
  • 输入#2

    5 1 1
    5 4 5 3 2 1
    

    输出#2

    1
    
  • 输入#3

    7 3 1
    4 1 3 5 7
    2 2 6
    1 4
    

    输出#3

    3
    
首页