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

题目大意:给出一个关注网络,检测在L内,一个用户发帖,最多有多少个转发量,像是宽度优先遍历,是有向图。

#include <iostream>
#include <algorithm>
#include <vector>
#include<queue>
using namespace std;
vector<int> user[];
int vis[];
int main() {
int n,L;
queue<int> qu;
cin>>n>>L;
int k,temp;
for(int i=;i<=n;i++){
cin>>k;
for(int j=;j<k;j++){
cin>>temp;
user[temp].push_back(i);
}
}
cin>>k;
int ct=,level=,num;
for(int i=;i<k;i++){
fill(vis,vis+n+,);//开心到哭泣,这里错了,导致过不去,因为编号是从1-n,所以就导致了最后一个点被赋值为1之后,一直为1.
cin>>temp;
ct=,level=;
while(!qu.empty())qu.pop();
qu.push(temp);
vis[temp]=;
qu.push(-);
while(level!=L){
while(!qu.empty()){
num=qu.front();
qu.pop();
if(num==-){
qu.push(-);
break;
}
for(int j=;j<user[num].size();j++){
if(!vis[user[num][j]]){
qu.push(user[num][j]);//将其放入
vis[user[num][j]]=;
ct++;
}
}
}
level++;
}
cout<<ct;
if(i!=k-)cout<<'\n';
}
return ;
}

我的AC代码,一般出现段错误就是数组长度设置的太小了,反正这次是这样。

1.还有一个困扰我的地方,“and that only L levels of indirect followers are counted.”,这里其实是很简单,并不是第一层的不算,所有的能转发的人都算在内。

PAT 1076 Forwards on Weibo[BFS][一般]的更多相关文章

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

  2. PAT 1076 Forwards on Weibo

    #include <cstdio> #include <cstdlib> #include <vector> #include <queue> #inc ...

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

  4. PAT甲级1076. Forwards on Weibo

    PAT甲级1076. Forwards on Weibo 题意: 微博被称为中文版的Twitter.微博上的一位用户可能会有很多关注者,也可能会跟随许多其他用户.因此,社会网络与追随者的关系形成.当用 ...

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

  6. 1076 Forwards on Weibo (30 分)

    1076 Forwards on Weibo (30 分) Weibo is known as the Chinese version of Twitter. One user on Weibo ma ...

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

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

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

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

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

随机推荐

  1. Microsoft 设计原则

    在本文中 关于现代设计 技术为本 实现以较少投入取得极大成绩 迅速和流畅 真正实现数字化 合作共赢 相关主题 驱动出色设计的基础 我们相信遵循 Microsoft 设计原则可帮助你构建使用户感到愉悦并 ...

  2. 【cs229-Lecture2】Linear Regression with One Variable (Week 1)(含测试数据和源码)

    从Ⅱ到Ⅳ都在讲的是线性回归,其中第Ⅱ章讲得是简单线性回归(simple linear regression, SLR)(单变量),第Ⅲ章讲的是线代基础,第Ⅳ章讲的是多元回归(大于一个自变量). 本文的 ...

  3. Word 2010 插入其他文件的方法

    1. 2.

  4. VMware ESXI5.5 Memories limits resolved soluation.

    在使用VMware ESXI5.5 的时候提示内存限制了,在网上找的了解决方案: 如下文: 1. Boot from VMware ESXi 5.5; 2. wait "Welcome to ...

  5. 理解proc目录与linux进程、ps命令、netstat命令的关系

    零.proc目录简介 proc目录是虚拟文件系统(VFS)的一种实现,保存了进程信息(pid目录)和一些系统信息. 一.系统的信息 1.cpuinfo和meminfo两个文件 查看CPU和内存相关信息 ...

  6. Dockerfile的一些demo

    tomcat7.0_jdk1.6 #继承用户创建的sshd镜像FROM yatho:sshd_ubuntu #创建者的基本信息 MAINTAINER yatho (yat_ho@163.com) #设 ...

  7. jQuery:find()方法与children()方法的区别

    1:children及find方法都用是用来获得element的子elements的,两者都不会返回 text node,就像大多数的jQuery方法一样. 2:children方法获得的仅仅是元素一 ...

  8. 【BZOJ1478】Sgu282 Isomorphism Pólya定理神题

    [BZOJ1478]Sgu282 Isomorphism 题意:用$m$种颜色去染一张$n$个点的完全图,如果一个图可以通过节点重新标号变成另外一个图,则称这两个图是相同的.问不同的染色方案数.答案对 ...

  9. iOS中self.xxx 和 _xxx 下划线的区别

    property (nonatomic,copy) NSString *propertyName; self.propertyName 是对属性的拜访: _propertyName 是对部分变量的拜访 ...

  10. How are you vs How are you doing

    How are you与How are you doing,有何不同呢? 貌似没有不同…… 中国教科书式的回答是"Fine, thank you, and you?" 随便一点&q ...