Model a story spreading through a social network where each person reposts only if a weighted sum of the story's categories equals their target.
Easy3GraphBFSSimulationNo attempts yetTime limit2sMemory limit512 MBFake news often travels through a social network. Someone posts a story that matches what a reader already believes, the reader accepts it with far less scrutiny than a story they disagree with, and the reader posts it too. The reader's friends see it next, and a story that panders hard enough can burn through a whole network. In this problem you simulate that spread. You are given the social network, the preferences of every individual, and the place where the story starts.
The model is simple, if a little unrealistic. There are r categories that matter to a reader, such as which political side the story flatters, how much sex it contains, or how much violence it contains. Individual j has an integer weight wj,i for category i, which may be positive or negative, and an integer target tj for total content. A story has an integer content ci for each category. Individual j likes a story exactly when ∑i=1rwj,ici=tj. The requirement is strict, but it is easy to compute. An individual who likes the story reposts it, and one who does not stays quiet. Everyone sees every story posted by a friend, and no story posted by anyone else unless a friend reposts it.
The story always starts at individual 1, who may still refuse to post it.
The first line contains K≥1, the number of data sets in the input. K data sets follow, each in the form below.
The first line of a data set contains two integers n and r, where 1≤n≤1000 is the number of individuals in the social network and 1≤r≤100 is the number of categories that matter for stories.
The next line contains exactly r integers c1 through cr, each between −100 and 100 inclusive.
Then come n lines, one for each individual j in order from 1 to n. The first r numbers on a line are wj,1 through wj,r, integers between −10 and 10 inclusive. Next comes tj, an integer between −1000000 and 1000000 inclusive. Next comes dj with 0≤dj≤n−1, the number of friends of j. After that come dj distinct integers between 1 and n, none of them equal to j, which are the friends of j. Friendship is always mutual: if j′ is a friend of j, then j is a friend of j′ as well.
The fake news story always starts at individual 1.
For each data set, print "Data Set x:" on a line by itself, where x is the number of the data set counting from 1. On the next line print the total number of people who have posted the fake news story once no one new posts. Print a blank line after each data set.