CF1185F.Two Pizzas
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A company of n friends wants to order exactly two pizzas. It is known that in total there are 9 pizza ingredients in nature, which are denoted by integers from 1 to 9 .
Each of the n friends has one or more favorite ingredients: the i -th of friends has the number of favorite ingredients equal to fi ( 1≤fi≤9 ) and your favorite ingredients form the sequence bi1,bi2,…,bifi ( 1≤bit≤9 ).
The website of CodePizza restaurant has exactly m ( m≥2 ) pizzas. Each pizza is characterized by a set of rj ingredients aj1,aj2,…,ajrj ( 1≤rj≤9 , 1≤ajt≤9 ) , which are included in it, and its price is cj .
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 n and m ( 1≤n≤105,2≤m≤105 ) — the number of friends in the company and the number of pizzas, respectively.
Next, the n lines contain descriptions of favorite ingredients of the friends: the i -th of them contains the number of favorite ingredients fi ( 1≤fi≤9 ) and a sequence of distinct integers bi1,bi2,…,bifi ( 1≤bit≤9 ).
Next, the m lines contain pizza descriptions: the j -th of them contains the integer price of the pizza cj ( 1≤cj≤109 ), the number of ingredients rj ( 1≤rj≤9 ) and the ingredients themselves as a sequence of distinct integers aj1,aj2,…,ajrj ( 1≤ajt≤9 ).
输出格式
Output two integers j1 and j2 ( 1≤j1,j2≤m , j1=j2 ) 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