时间限制
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++/CLR Sqlite初探

        error C2491: "acosh": 不允许 dllimport 函数 的定义     asinh": 不允许 dllimport 函数 的定义     a ...

  2. Java中 return 和finally

    1. 最简单的情形 public void main(){ String s = test(); System.out.println("s=[" + s + "]&qu ...

  3. Android(java)学习笔记116:PC_Phone通信程序报错

    1.首先我写的程序代码如下: package com.himi.udpsend; import java.net.DatagramPacket; import java.net.DatagramSoc ...

  4. html中input type=file 改变样式

    <style> #uploadImg{ font-size:12px; overflow:hidden; position:absolute} #file{ position:absolu ...

  5. Linux vsftp

    本机环境CentOS-6.6-i386-bin-DVD1.iso安装盘.安装时选择minimal模式.本机IP地址配置为192.168.0.211. 1.查询系统是否已安装了vsftpd [root@ ...

  6. windows 端搭建nfs 服务器

    因为最近虚拟机桥连模式总是用不了会出问题,所以今天花了半个小时研究了一下在Windows主机下搭建一个nfs服务器进行文件传输. 其实步骤很简单,如下: 1. 下载NFS Windows服务器软件,我 ...

  7. Repeater控件中的LinkButton(转)

    LinkButton小用法: 1.在使用时可以通过CommandName和CommandArgument属性联合起来绑定并传值,如:CommandName="record"Comm ...

  8. 关于Winform发布时,资源文件缺失的解决方案

    今天和大家分享一下,我这几天一直困惑的问题,今天不经意间解决了这个问题,接下来描述一下这个问题: 问题: 最近公司给人家做二次开发,是C/S结构的,我在做Winform时发现,当我选择一个项目发布时, ...

  9. Jersey(1.19.1) - Life-cycle of Root Resource Classes

    By default the life-cycle of root resource classes is per-request, namely that a new instance of a r ...

  10. 运用NPOI操作EXCEL

    一.引入NPOI程序集 下载地址:http://pan.baidu.com/s/1qWI3Vgo 二.运用NPOI导出成excel文件 protected void btnOutExcel_Click ...