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 counted.

Sample Input:

7 3
3 2 3 4
0
2 5 6
2 3 1
2 3 4
1 4
1 5
2 2 6

Sample Output:

4
5
/*  题目大意是: 一个微博用户发帖 根据关注他的人数 求最大可能被转载的次数 而且最多只能被间接转载m-1次
注意:和六度空间基本相同 但这里是单向图
*/
#include "iostream"
#include "queue"
using namespace std;
int Count;
bool map[][] = {false};
int n, m;
void bfs(int x) {
Count = ;
bool visited[] = {false};
queue<int>q;
q.push(x);
visited[x] = true;
int last = x;
int tail;
int level = ;
while (!q.empty()) {
x = q.front();
q.pop();
for (int i = ; i <= n; i++) {
if (map[x][i] == && !visited[i]) {
Count++;
visited[i] = ;
tail = i;
q.push(i);
}
}
if (last == x) {
level++;
last = tail;
}
if (level == m)
break;
}
}
int main() {
cin >> n >> m;
for (int i = ; i <= n; i++) {
int l;
cin >> l;
while (l--) {
int x;
cin >> x;
map[x][i] = ;
}
}
int k;
cin >> k;
while (k--) {
int x;
cin >> x;
bfs(x);
cout << Count << endl;
}
return ;
}

PAT 1076. Forwards on Weibo (30)的更多相关文章

  1. 1076. Forwards on Weibo (30)【树+搜索】——PAT (Advanced Level) Practise

    题目信息 1076. Forwards on Weibo (30) 时间限制3000 ms 内存限制65536 kB 代码长度限制16000 B Weibo is known as the Chine ...

  2. PAT 甲级 1076 Forwards on Weibo (30分)(bfs较简单)

    1076 Forwards on Weibo (30分)   Weibo is known as the Chinese version of Twitter. One user on Weibo m ...

  3. PAT 1076 Forwards on Weibo[BFS][一般]

    1076 Forwards on Weibo (30)(30 分) Weibo is known as the Chinese version of Twitter. One user on Weib ...

  4. PAT Advanced 1076 Forwards on Weibo (30) [图的遍历,BFS,DFS]

    题目 Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and ...

  5. PAT (Advanced Level) 1076. Forwards on Weibo (30)

    最短路. 每次询问的点当做起点,然后算一下点到其余点的最短路.然后统计一下最短路小于等于L的点有几个. #include<cstdio> #include<cstring> # ...

  6. PAT甲题题解-1076. Forwards on Weibo (30)-BFS

    题目大意:给出每个用户id关注的人,和转发最多的层数L,求一个id发了条微博最多会有多少个人转发,每个人只考虑转发一次.用BFS,同时每个节点要记录下所在的层数,由于只能转发一次,所以每个节点要用vi ...

  7. 【PAT甲级】1076 Forwards on Weibo (30 分)

    题意: 输入两个正整数N和L(N<=1000,L<=6),接着输入N行数据每行包括它关注人数(<=100)和关注的人的序号,接着输入一行包含一个正整数K和K个序号.输出每次询问的人发 ...

  8. 1076. Forwards on Weibo (30)

    时间限制 3000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Weibo is known as the Chinese v ...

  9. 1076. Forwards on Weibo (30) - 记录层的BFS改进

    题目如下: Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, a ...

随机推荐

  1. 关于angular 自定义directive

    关于angular 自定义directive的小结 首先我们创建一个名为"expander"的自定义directive指令: angular.module("myApp& ...

  2. skymvc网站测试之mysql数据生成

    skymvc网站测试之mysql数据生成 使用方法: 删除数据 /index.php?m=test_mysql&a=autoDelete 重置自增ID /index.php?m=test_my ...

  3. Excel Skill (1) -- 判断时如何去掉框里的空格

    使用命令 TRIM 说明: Purpose. Remove extra spaces from text. Text with extra spaces removed. =TRIM (text) t ...

  4. How to new a screen in linux

    screen -R -D: create a screen Ctrl + A & Ctrl + D: leave a screen

  5. c语言命名规则 [转载]

    C语言变量名命名规则 一.程序风格:         1.严格采用阶梯层次组织程序代码:         各层次缩进的分格采用VC的缺省风格,即每层次缩进为4格,括号位于下一行.     要求相匹配的 ...

  6. SPRING IN ACTION 第4版笔记-第一章-005-Bean的生命周期

    一. 1. As you can see, a bean factory performs several setup steps before a bean is ready touse. Let’ ...

  7. javascript外部使用

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. LA_3263_That_Nice_Euler_Circuits_(欧拉定理+计算几何基础)

    描述 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=15& ...

  9. (转载)AS3领航系列教程 之 AS3程序的入口

    (转载)http://blog.csdn.net/wibrst/article/details/1861828 要实践本教程, 您需要安装以下软件:    Flash CS3 AS3程序的入口 众所周 ...

  10. HDU-1686 Oulipo

    学习:重点理解这句话的意思: next[j]会告诉我们从哪里开始匹配     模板题. Oulipo Time Limit: 3000/1000 MS (Java/Others)    Memory ...