CF1185F.Two Pizzas

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

A company of nn friends wants to order exactly two pizzas. It is known that in total there are 99 pizza ingredients in nature, which are denoted by integers from 11 to 99 .

Each of the nn friends has one or more favorite ingredients: the ii -th of friends has the number of favorite ingredients equal to fif_i ( 1fi91 \le f_i \le 9 ) and your favorite ingredients form the sequence bi1,bi2,,bifib_{i1}, b_{i2}, \dots, b_{if_i} ( 1bit91 \le b_{it} \le 9 ).

The website of CodePizza restaurant has exactly mm ( m2m \ge 2 ) pizzas. Each pizza is characterized by a set of rjr_j ingredients aj1,aj2,,ajrja_{j1}, a_{j2}, \dots, a_{jr_j} ( 1rj91 \le r_j \le 9 , 1ajt91 \le a_{jt} \le 9 ) , which are included in it, and its price is cjc_j .

Help your friends choose exactly two pizzas in such a way as to please the maximum number of people in the company. It is known that a person is pleased with the choice if each of his/her favorite ingredients is in at least one ordered pizza. If there are several ways to choose two pizzas so as to please the maximum number of friends, then choose the one that minimizes the total price of two pizzas.

输入格式

The first line of the input contains two integers nn and mm ( 1n105,2m1051 \le n \le 10^5, 2 \le m \le 10^5 ) — the number of friends in the company and the number of pizzas, respectively.

Next, the nn lines contain descriptions of favorite ingredients of the friends: the ii -th of them contains the number of favorite ingredients fif_i ( 1fi91 \le f_i \le 9 ) and a sequence of distinct integers bi1,bi2,,bifib_{i1}, b_{i2}, \dots, b_{if_i} ( 1bit91 \le b_{it} \le 9 ).

Next, the mm lines contain pizza descriptions: the jj -th of them contains the integer price of the pizza cjc_j ( 1cj1091 \le c_j \le 10^9 ), the number of ingredients rjr_j ( 1rj91 \le r_j \le 9 ) and the ingredients themselves as a sequence of distinct integers aj1,aj2,,ajrja_{j1}, a_{j2}, \dots, a_{jr_j} ( 1ajt91 \le a_{jt} \le 9 ).

输出格式

Output two integers j1j_1 and j2j_2 ( 1j1,j2m1 \le j_1,j_2 \le m , j1j2j_1 \ne j_2 ) denoting the indices of two pizzas in the required set. If there are several solutions, output any of them. Pizza indices can be printed in any order.

输入输出样例

  • 输入#1

    3 4
    2 6 7
    4 2 3 9 5
    3 2 3 9
    100 1 7
    400 3 3 2 5
    100 2 9 2
    500 3 2 9 5
    

    输出#1

    2 3
    
  • 输入#2

    4 3
    1 1
    1 2
    1 3
    1 4
    10 4 1 2 3 4
    20 4 1 2 3 4
    30 4 1 2 3 4
    

    输出#2

    1 2
    
  • 输入#3

    1 5
    9 9 8 7 6 5 4 3 2 1
    3 4 1 2 3 4
    1 4 5 6 7 8
    4 4 1 3 5 7
    1 4 2 4 6 8
    5 4 1 9 2 8
    

    输出#3

    2 4
    
首页