1076 Forwards on Weibo (30 分)

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

注意点:1、按序输入i的关注temp, Follower[temp].push(i)    2、尽量避免使用inq[maxn]={0}(当BFS第二次运行这条语句时会出现未初始化),用memset或者fill代替即可。。 这里检查了半天。。 

 /**
 * Copyright(c)
 * All rights reserved.
 * Author : Mered1th
 * Date : 2019-02-22-13.18.58
 * Description : A1076
 */
 #include<cstdio>
 #include<cstring>
 #include<iostream>
 #include<cmath>
 #include<algorithm>
 #include<string>
 #include<unordered_set>
 #include<map>
 #include<vector>
 #include<set>
 #include<queue>
 using namespace std;
 ;
 int n,l,k,level,sum;
 bool inq[maxn];
 struct node{
     int id,layer;
 };
 vector<node> Follower[maxn];
 void BFS(int u){
     sum=;
     memset(inq,,sizeof(inq));
     queue<node> q;
     node st;
     st.id=u,st.layer=;
     q.push(st);
     inq[u]=true;
     while(!q.empty()){
         node top=q.front();
         q.pop();
         int x=top.id;
         int siz=Follower[x].size();
         ;i<Follower[x].size();i++){
             node v=Follower[x][i];
             v.layer=top.layer+;
             if(inq[v.id]==false && v.layer<=l){
                 q.push(v);
                 inq[v.id]=true;
                 sum++;
             }
         }
     }
 }
 int main(){
 #ifdef ONLINE_JUDGE
 #else
     freopen("1.txt", "r", stdin);
 #endif
     node user;
     scanf("%d%d",&n,&l);
     int t,temp,query;
     ;i<=n;i++){
         user.id=i;
         scanf("%d",&t);
         ;j<t;j++){
             scanf("%d",&temp);
             Follower[temp].push_back(user);
         }
     }
     scanf("%d",&k);
     ;i<k;i++){
         scanf("%d",&query);
         BFS(query);
         printf("%d\n",sum);
     }

     ;
 }
 

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

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

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

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

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

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

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

  6. 1076. Forwards on Weibo (30)

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

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

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

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

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

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

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

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

随机推荐

  1. docker容器,镜像常用操作

    1.查看正在运行的容器 docker ps 查看所有容器 docker ps -a 2.查看容器日志 docker logs -f showdoc 3.删除所有容器 docker rm $(docke ...

  2. Windows 7 + PHP 5.3 + WAMP 下 Imagick 扩展安装

    1.首先,下载 ImageMagick 安装包.下载地址 下载后运行此安装包.在系统环境变量中添加 MAGICK_HOME 变量,指向安装目录下的modules\coders. 2.下载 Imagic ...

  3. js 常用事件

    onclick 事件会在对象被点击时发生. 请注意, onclick 与 onmousedown 不同.单击事件是在同一元素上发生了鼠标按下事件之后又发生了鼠标放开事件时才发生的. 如:点击验证码时进 ...

  4. php session和cookie知识

  5. APP测试重点罗列

    1.安装和卸载 应用是否可以在IOS不同系统版本或android不同系统版本上安装(有的系统版本过低,应用不能适配) 软件安装后是否可以正常运行,安装后的文件夹及文件是否可以写到指定的目录里. 安装过 ...

  6. 10款PHP开源网店系统

    在当今经济危机的大环境下,网上购物越来越来吃香,网上开店成本低,快捷方便,出名的电子商务网站有淘宝,拍拍,Ebay或是最新的百度有啊,这些网站都提供开店的机会,如果是想自己搭建购物平台,可以从下面选择 ...

  7. 纯CSS绘制三角形(各种角度)类似于使用字符画法,根据位移不同,也可以使用两个元素画出三角边框

    我们的网页因为 CSS 而呈现千变万化的风格.这一看似简单的样式语言在使用中非常灵活,只要你发挥创意就能实现很多比人想象不到的效果.特别是随着 CSS3 的广泛使用,更多新奇的 CSS 作品涌现出来. ...

  8. python表单验证封装

    在Web程序中往往包含大量的表单验证的工作,如:判断输入是否为空,是否符合规则. <!DOCTYPE html><html><head lang="en&quo ...

  9. IBM DS存储存储性能调优

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/jaminwm/article/details/26458791 ibm存储适用,其它存储有相似參数. ...

  10. 使用C#和MSMQ开发消息处理程序

    简介 MSMQ(微软消息队列)是Windows操作系统中消息应用程序的基础,是用于创建分布式.松散连接的消息通讯应用程序的开发工具.消息队列和电子邮件有着很多相似处,他们都包含多个属性,用于保存消息, ...