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. php类的属性

    属性声明是由关键字 public,protected 或者 private 开头,后面跟一个普通的变量声明来组成.属性的变量可以设置初始化的默认值,默认值必须是常量. class Car { //定义 ...

  2. PHP实现多web服务器共享SESSION数据-session数据写入mysql数据库

    http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2010/0822/5276.html http://hi.baidu.com/lei_com/ ...

  3. linux 配置apache+subversion

    http://apr.apache.org/download.cgi http://subversion.tigris.org/servlets/ProjectDocumentList?folderI ...

  4. 为什么很多语言选择在JVM上实现

    非常经济地实现跨平台.你的语言编译器后端只需要输出 JVM 字节码就可以.跨平台需要极大的工作量,举个例子,只是独立开发生成本地代码,就需要花费大量精力去针对不同平台和处理器进行优化(比如 Firef ...

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

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

  6. ios开发之C语言第3天

    变量的命名规则以及规范 变量的命名规则  1>变量名只能由任意的字母,下划线和$以及数字组成,注意不能用数字开头 2>区分大小写 3>变量一定要先定义再使用 4>同一个大括号中 ...

  7. CommonsChunkPlugin的一些总结

    CommonsChunkPlugin 官方文档地址 https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin new ...

  8. 第 12 章 命令模式【Command Pattern】

    以下内容出自:<<24种设计模式介绍与6大设计原则>> 今天讲命令模式,这个模式从名字上看就很简单,命令嘛,老大发命令,小兵执行就是了,确实是这个意思,但是更深化了,用模式来描 ...

  9. 任正非:华为三十年大限快到了 想不死就得新生(建立战略预备队)cool

    华为心声社区官方微信今日发布了任正非8月15日在华为公司内部做的关于战略预备队建设汇报的讲话.讲话内容中提到,华为公司需要组织.结构.人才等所有一切都变化,通过变化使新的东西成长起来.   任正非表示 ...

  10. [cocos2d]调用sqlite3数据库

    开发一个小项目需要用到已有的数据库,而数据库的文件存储方式是csv,即数据用','分隔, 1.csv文件转换成sqlite 由于ios自带sqlite3的组件,所以先把csv文件转成sqlite数据库 ...