天天看点

Pat(Advanced Level)Practice--1076(Forwards on Weibo)Pat1076代码

题目描述:

weibo is known as the chinese version of twitter. one user on weibo may have many followers, and may follow many other users as well. hence a social network is formed with followers relations. when a user makes a post on weibo, all his/her followers can view

and forward his/her post, which can then be forwarded again by their followers. now given a social network, you are supposed to calculate the maximum potential amount of forwards for any specific user, assuming that only l levels of indirect followers are

counted.

input specification:

each input file contains one test case. for each case, the first line contains 2 positive integers: n (<=1000), the number of users; and l (<=6), the number of levels of indirect followers that are counted. hence it is assumed that all the users are numbered

from 1 to n. then n lines follow, each in the format:

m[i] user_list[i]

where m[i] (<=100) is the total number of people that user[i] follows; and user_list[i] is a list of the m[i] users that are followed by user[i]. it is guaranteed that no one can follow oneself. all the numbers are separated

by a space.

then finally a positive k is given, followed by k userid‘s for query.

output specification:

for each userid, you are supposed to print in one line the maximum potential amount of forwards this user can triger, assuming that everyone who can view the initial post will forward it once, and that only l levels of indirect followers are

sample input:

sample output:

ac代码:

bfs层数计数问题;最后一个case居然跑了2200ms,差点就超时了;思路是bfs肯定没错。