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. 通俗大白话来理解TCP协议的三次握手和四次分手

    通俗理解: 但是为什么一定要进行三次握手来保证连接是双工的呢,一次不行么?两次不行么?我们举一个现实生活中两个人进行语言沟通的例子来模拟三次握手. 引用网上的一些通俗易懂的例子,虽然不太正确,后面会指 ...

  2. 提交代码到自己的github仓库

    说起来尴尬,好几年前就搞了github建了仓库,当时玩得还有点6,后来一直的公司都是svn,自己业务项目也没玩,都忘了要怎么提交代码到自己的仓库了. 这边再来一波记录吧. 一.配置用户名 git co ...

  3. mysql架构图

    整体架构图 访问控制图

  4. 使用spring提供的ReflectionUtils简化项目中反射代码的复杂性

    在项目中有时候我们会使用到反射的功能,如果使用最原始的方法来开发反射的功能的话肯能会比较复杂,需要处理一大堆异常以及访问权限等问题.spring中提供了ReflectionUtils 这个反射的工具类 ...

  5. 学会阅读Java字节码

    1.Class文件基础   (1)文件格式     Class文件的结构不像XML等描述语言那样松散自由.由于它没有任何分隔符号, 所以,以上数据项无论是顺序还是数量都是被严格限定的.哪个字节代表什么 ...

  6. 【CF913F】Strongly Connected Tournament 概率神题

    [CF913F]Strongly Connected Tournament 题意:有n个人进行如下锦标赛: 1.所有人都和所有其他的人进行一场比赛,其中标号为i的人打赢标号为j的人(i<j)的概 ...

  7. HTML 5 Audio/Video DOM canplaythrough 事件在移动端遇到的坑

    canplaythrough 事件定义和用法 当浏览器预计能够在不停下来进行缓冲的情况下持续播放指定的音频/视频时,会发生 canplaythrough 事件. 当音频/视频处于加载过程中时,会依次发 ...

  8. Xcode - Xcodeproject详解

    前言 在 iOS 开发过程中,我们经常会在 Xcode 里面做一些配置,比如添加系统库.第三方库,修改证书配置文件,修改编译属性等等. 在这个过程里面,一般大家仅仅只是根据经验来配置这些,并没有比较清 ...

  9. linux文件归档脚本

    #!/bin/bash range= dir="/app/xx/logs" bak_dir="/app/xx/logs_archive" cd $dir $ra ...

  10. openstack 部署(Q版)-----glance镜像服务安装配置

    一.创建数据库 CREATE DATABASE glance; GRANT ALL PRIVILEGES ON glance.* TO '; GRANT ALL PRIVILEGES ON glanc ...