Suspicious Orders
Time limit1sMemory limit128 MB
Count the cliques in a network of up to 20 people whose combined ordered items cover at least one of the given attack combinations.
- Level
Medium6 of 10
- Topics
- Backtracking, Bit manipulation, Graph
- Solved
- No attempts yet
Problem
A family once got an unexpected visit from the FBI. The wife had been searching for pressure cookers on the family computer, and the husband had been looking at backpacks. It was right after the Boston Marathon bombing, where the explosives were pressure cookers hidden in backpacks.
Someone who wants to avoid detection does not search for or order every material of an attack himself. A group can split the orders among its members instead, so a record of who knows whom helps in spotting that pattern.
You are given every social connection in a network, and for each person the list of items that person ordered or looked at online. A clique is a set of people in which every two members are connected to each other. You are also given lists of items that together can be used for an attack. Say items together are enough to start an attack. Then a clique whose orders add up to can carry out an attack as well. Count how many cliques in the data could carry out an attack with what they ordered.
One person may already have ordered all the materials alone. Every clique containing that person then has all the materials too, so many cliques can be counted for the same materials. That is correct.
Input
The first line contains the number of data sets, followed by the data sets, each of the following form.
The first line of a data set contains four integers , , , , separated by spaces. is the number of people in the network, is the number of items whose purchases are tracked, is the number of item combinations that can be used for an attack, and is the number of connections in the network.
This is followed by lines, each describing one combination of materials that can be used for an attack. Each such line contains as its first number an integer (), the number of items this combination contains. This is followed by integers on the same line, each between and .
Next come lines describing the items that the corresponding person bought. Line starts with a number (), the number of items person bought. Then follow integers between and , each giving an item.
Finally, there are lines, each containing two distinct integers between and , describing a connection between those two people.
Output
For each data set, print Data Set x: on a line by itself, where is its number. On the next line, print the number of different cliques of one or more people that could carry out an attack by pooling their materials. Print a blank line between consecutive data sets.