时间限制
3000 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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
 #include<stdio.h>
#include<vector>
#include<queue>
using namespace std; struct Node
{
int ID;
int level;
};
vector<Node> Grap[];
bool visit[]; void inth(int n)
{
for(int i = ; i<= n;i++)
visit[i]=false;
} int main()
{
int i,n,num,j,tem,L,Count;
Node Ntem;
scanf("%d%d",&n,&L);
for(i = ; i<= n ;i++ )
{
scanf("%d",&num);
for(j = ; j < num ;j++)
{
scanf("%d",&tem);
Ntem.ID = i ;
Grap[tem].push_back(Ntem);
}
} int k;
scanf("%d",&k);
for(i = ; i < k;i++)
{
inth(n);
Count = ;
scanf("%d",&tem);
Ntem.ID = tem;
Ntem.level = ;
queue<Node> Gqueue;
Gqueue.push(Ntem);
visit[Ntem.ID] = true;
while(! Gqueue.empty())
{
Ntem = Gqueue.front();
if(Ntem.level > L) break;
++Count ; Gqueue.pop();
for(j = ;j < Grap[Ntem.ID].size();j++)
{
if(! visit[ Grap[Ntem.ID][j].ID ])
{
Grap[Ntem.ID][j].level = Ntem.level + ;
visit[ Grap[Ntem.ID][j].ID ] = true;
Gqueue.push(Grap[Ntem.ID][j]);
}
}
} printf("%d\n",Count-);
} return ;
}

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 (30)

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

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

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

  5. 1076 Forwards on Weibo (30)(30 分)

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

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

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

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

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

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

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

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

随机推荐

  1. 网站安全通用防护代码(C#版本源码提供)

    每一个开发者都会意识到,网站发布之前,需要进行安全检查. 那么如何拦截攻击者注入恶意代码?如何防御诸如跨站脚本攻击(XSS).SQL注入攻击等恶意攻击行为? 针对目前常见的一些安全问题,结合目前一些常 ...

  2. javascript的变量、作用域和内存问题

    基本类型和引用类型的值执行环境垃圾收集 ECMAScript 变量可能包含两种不同数据类型的值:基本类型值和引用类型值.基本类型值指的是简单的数据段引用类型值指那些可能由多个值构成的对象 基本数据类型 ...

  3. height、clientHeight、scrollHeight、offsetHeight区别

    转自 http://www.cnblogs.com/yuteng/articles/1894578.html 我们来实现test中的onclick事件    function justAtest()  ...

  4. android源码编译常见错误

    错误1:You are attempting to build on a 32-bit system. Only 64-bit build environments are supported bey ...

  5. [Java]java反射随笔

    类是面向对象的灵魂,一切事物都可以以类来抽象. 在java使用过程中,我们可能会经常用到一个反射的知识,只是别人都封装好的,如jdbc的加载驱动类有一句Class.for(“…jdbc…”).newI ...

  6. Kali+Win7双系统

    ----------------------------------------------------------前言---------------------------------------- ...

  7. Next Power of 2

    Next Power of 2 Write a function that, for a given no n, finds a number p which is greater than or e ...

  8. bootstrap学习起步篇:初识bootstrap之表单验证(二)

    学习bootstrap是个过程,它提供给我们的文档上有很详细的说明.包括常用的栅栏布局.页面元素等,这里就不啰嗦了,今天,我就来说下结合jquery的表单验证. 最开始不借助插件,我们需要自己去编写验 ...

  9. HDOJ2002计算球体积

    计算球体积 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  10. ContentProvider(一)

    注册ContentProvider: <provider android:name=".provider.UserProvider" android:authorities= ...