时间限制
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. Linux 修改swap虚拟内存大小

          swap是内存的交换区:换句话说,如果内存不够用了,那么系统会在硬盘上存储一些内存中不常用的数据,之后将这部分数据在存储中析构掉:这样内存就又有剩余空间可以运行东东啦,这个过程也就是所谓的 ...

  2. AngularJs学习经验汇集

    >>关于ng-include 有时候你会发现你用这个指令想要加载某个模板总是加载不出来,url明明是对的,页面还是一片空白,这里有一个细节要注意以下: <div ng-include ...

  3. linux mail 配置

    1:sudo apt-get install sendmail sendmail-cf2:ps aux | grep sendmail3.配置/etc/mail/sendmail.mc    FEAT ...

  4. [改善Java代码]不要在finally块中处理返回值

    在finally代码块中处理返回值,这是在面试题中经常出现的题目.但是在项目中绝对不能再finally代码块中出现return语句,这是因为这种处理方式非常容易产生"误解",会严重 ...

  5. Java多线程原理

    学过Java的人都知道,Java是少数的集中支持多线程的语言之一,大多数的语言智能运行单独的一个程序块,无法同时运行不同的多个程序块,Java的多线程机制弥补了这个缺憾,他可以让不同的程序块一起运行, ...

  6. 【原创】 windows下开发软件推荐

    1. 数据库查看器工具 navicat.exe

  7. java下实现调用oracle的存储过程和函数

    在Oracle下创建一个test的账户,然后 1.创建表:STOCK_PRICES --创建表格 CREATE TABLE STOCK_PRICES( RIC VARCHAR() PRIMARY KE ...

  8. Codevs 3729==洛谷P1941 飞扬的小鸟

    P1941 飞扬的小鸟 456通过 2.4K提交 题目提供者该用户不存在 标签动态规划2014NOIp提高组 难度提高+/省选- 提交该题 讨论 题解 记录   题目描述 Flappy Bird 是一 ...

  9. Git基本命令和GitFlow工作流

    本篇博客讲解了git的一些基本的团队协作命令,和GitFlow工作流指南 git 团队协作的一些命令 1.开分支 git branch 新分支名 例如,在master分支下,新开一个开发分支: git ...

  10. Sqlite事物与锁

    1事务 事务定义了一组SQL命令的边界,这组命令或者作为一个整体被全部执行,或者都不执行.事务的典型实例是转帐. 2事务的范围 事务由3个命令控制:BEGIN.COMMIT和ROLLBACK.BEGI ...