CF1185F.Two Pizzas

提高+/省选-

通过率:0%

时间限制:4.00s

内存限制:256MB

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 (1≤fi≤91 \le f_i \le 9) and your favorite ingredients form the sequence bi1,bi2,…,bifib_{i1}, b_{i2}, \dots, b_{if_i} (1≤bit≤91 \le b_{it} \le 9).

The website of CodePizza restaurant has exactly mm (m≥2m \ge 2) pizzas. Each pizza is characterized by a set of rjr_j ingredients aj1,aj2,…,ajrja_{j1}, a_{j2}, \dots, a_{jr_j} (1≤rj≤91 \le r_j \le 9, 1≤ajt≤91 \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.

一家由 nn 位朋友组成的团体想要恰好订购两张披萨。已知自然界中总共有 99 种披萨配料,分别用整数 11 到 99 表示。

这 nn 位朋友中的每一位都拥有一种或多种喜爱的配料:第 ii 位朋友喜爱的配料数量为 fif_i(1≤fi≤91 \le f_i \le 9),其喜爱的配料序列为 bi1,bi2,…,bifib_{i1}, b_{i2}, \dots, b_{if_i}(其中 1≤bit≤91 \le b_{it} \le 9)。

CodePizza 餐厅网站上恰好有 mm(m≥2m \ge 2)种披萨可供选择。每种披萨 jj 由其所含的 rjr_j 种配料 aj1,aj2,…,ajrja_{j1}, a_{j2}, \dots, a_{jr_j}(1≤rj≤91 \le r_j \le 9,且 1≤ajt≤91 \le a_{jt} \le 9)所刻画,其价格为 cjc_j。

请帮助这群朋友恰好挑选两张披萨,使得尽可能多的朋友感到满意。已知:当某位朋友的所有喜爱配料均至少出现在所选的两张披萨之一中时,该朋友即被取悦。若存在多种方式可选出两张披萨以取悦最多数量的朋友,则在这些方案中选择总价格最小的一种。

输入格式

The first line of the input contains two integers nn and mm (1≤n≤105,2≤m≤1051 \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 (1≤fi≤91 \le f_i \le 9) and a sequence of distinct integers bi1,bi2,…,bifib_{i1}, b_{i2}, \dots, b_{if_i} (1≤bit≤91 \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 (1≤cj≤1091 \le c_j \le 10^9), the number of ingredients rjr_j (1≤rj≤91 \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} (1≤ajt≤91 \le a_{jt} \le 9).

输入的第一行包含两个整数 nn 和 mm(1≤n≤1051 \le n \le 10^5,2≤m≤1052 \le m \le 10^5),分别表示公司中朋友的数量和披萨的数量。

接下来的 nn 行描述了每位朋友喜爱的食材:其中第 ii 行包含一个整数 fif_i(1≤fi≤91 \le f_i \le 9)以及一个由 fif_i 个互不相同的整数构成的序列 bi1,bi2,…,bifib_{i1}, b_{i2}, \dots, b_{if_i}(1≤bit≤91 \le b_{it} \le 9),分别表示第 ii 位朋友喜爱的食材种类数及其具体喜爱的食材编号。

接下来的 mm 行描述了每种披萨的信息:其中第 jj 行包含一个整数 cjc_j(1≤cj≤1091 \le c_j \le 10^9)表示该披萨的价格,一个整数 rjr_j(1≤rj≤91 \le r_j \le 9)表示该披萨所含的食材种类数,以及一个由 rjr_j 个互不相同的整数构成的序列 aj1,aj2,…,ajrja_{j1}, a_{j2}, \dots, a_{jr_j}(1≤ajt≤91 \le a_{jt} \le 9),表示该披萨所含的具体食材编号。

输出格式

Output two integers j1j_1 and j2j_2 (1≤j1,j2≤m1 \le j_1,j_2 \le m, j1≠j2j_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.

输出两个整数 j1j_1 和 j2j_2(1≤j1,j2≤m1 \le j_1,j_2 \le m,且 j1≠j2j_1 \ne j_2),表示所要求集合中两个披萨的索引。若存在多种解,输出任意一种即可。披萨索引的输出顺序可以任意。

输入输出样例

  • 输入#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

输入解题思路,AI测评打分。不知道怎么写?

首页