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 分)的更多相关文章
- 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 ...
 - 【PAT甲级】1076 Forwards on Weibo (30 分)
		
题意: 输入两个正整数N和L(N<=1000,L<=6),接着输入N行数据每行包括它关注人数(<=100)和关注的人的序号,接着输入一行包含一个正整数K和K个序号.输出每次询问的人发 ...
 - 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 ...
 - 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 ...
 - 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 ...
 - 1076. Forwards on Weibo (30)
		
时间限制 3000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Weibo is known as the Chinese v ...
 - 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 ...
 - 1076. Forwards on Weibo (30) - 记录层的BFS改进
		
题目如下: Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, a ...
 - PAT (Advanced Level) 1076. Forwards on Weibo (30)
		
最短路. 每次询问的点当做起点,然后算一下点到其余点的最短路.然后统计一下最短路小于等于L的点有几个. #include<cstdio> #include<cstring> # ...
 - PAT甲题题解-1076. Forwards on Weibo (30)-BFS
		
题目大意:给出每个用户id关注的人,和转发最多的层数L,求一个id发了条微博最多会有多少个人转发,每个人只考虑转发一次.用BFS,同时每个节点要记录下所在的层数,由于只能转发一次,所以每个节点要用vi ...
 
随机推荐
- iOS ipv6 被拒
			
1.检查你所用到的库,像af 3.0以上什么的(不用改),其他的库自己去搜下是否支持ipv6吧. 2.确保你用的sdk支持ipv6,这个自己去看文档就行. 3.终端 dig +nocmd + nos ...
 - 掌握 javascript 核心概念 最好的教程 系列 之一
			
链接 新链接 函数优先, 在扫描创建变量阶段, 会先收集函数, 如果前面有同名函数或者变量, 这个新函数会覆盖前面同名的: 而如果这时候是变量, 则不能去覆盖前面已有的值. function test ...
 - SSH项目搭建(三)——Maven多模块搭建项目
			
多模块开发,大致的思想就是把一个项目按某种方式分成多个模块,再把模块们连接成一个整体,我们在开发的时候,可以很清晰的操作每一个模块,可以大大提高开发的效率. Java web项目,最常见的就是按代码的 ...
 - P1002 谁拿了最多奖学金
			
P1002 谁拿了最多奖学金 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 NOIP2005复赛提高组第一题 描述 某校的惯例是在每学期的期末考试之后发放奖 ...
 - Qt 获取组合键 键盘按住某键  鼠标组合实现
			
#include "mainwindow.h" #include <QDebug> #include <QKeyEvent> #include <QM ...
 - SharePoint 2010: Change welcome page on PowerShell
			
摘要: SharePoint 2010之后呢, 建立一个 Team Site会有两个 default page, 分别是 Sitepages/home.aspx and default.aspx. 这 ...
 - 如何查看linux系统的版本信息
			
前言 有时候需要查看linux系统的版本信息,本文将对此简单介绍. 方法 1.输入"uname -a ",可显示电脑以及操作系统的相关信息. 2.输入"cat /etc/ ...
 - ubuntu安装sublime教程
			
1.安装Sublime Text 3 及常用的神器插件 ①首先添加sublime text 3的仓库:sudo add-apt-repository ppa:webupd8team/sublime-t ...
 - android 学习过程中登陆失效的个人理解
			
今天在学习的过程中,要做登陆失效的功能,所以就找了些资料.好好看了一下.研究了一番,慢慢的做出来了! 比方:你在一个手机端登陆了账号,在另外的一个手机端也登陆了账号,此时.前一个手机端的账号会提示登陆 ...
 - 树莓派挂载和卸载U盘或移动硬盘
			
通常我们在 /mnt 或 /media 目录下新建一个目录udisk作为挂载点 sudo mkdir /mnt/udisk 1.手动挂载: 挂载命令: sudo mount -o uid=pi,gid ...