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 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)的更多相关文章
- 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 ...
- 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)
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 ...
- 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 ...
- 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 ...
- 【PAT甲级】1076 Forwards on Weibo (30 分)
题意: 输入两个正整数N和L(N<=1000,L<=6),接着输入N行数据每行包括它关注人数(<=100)和关注的人的序号,接着输入一行包含一个正整数K和K个序号.输出每次询问的人发 ...
随机推荐
- python django第二弹
每天晚上应该就这样坐着,然后把每天的东西做个总结,或大或小,有的人可能愿意把自己的东西保留在草稿箱,想想我还是把他写出来吧,前几次我发现又遇到了之前遇到的简单的问题,翻看自己之前写的几篇小日记,可以很 ...
- 关于使用vss版本管理工具中的sln,suo文件作用
Visual Studio.NET采用两种文件类型(.sln和.suo)来存储特定于解决方案的设置,它们总称为解决方案文件.为解决方案资源管理器提供显示管理文件的图形接口所需的信息 从而在每次继续开发 ...
- Java从Jar文件中动态加载类
动态加载jar包,在实际开发中经常会需要用到,尤其涉及平台和业务的关系的时候,业务逻辑部分可以独立出去交给业务方管理,业务方只需要提供jar包,就能在平台上运行. 下面通过一个实例来直观演示: 第一: ...
- Java Concurrency - Semaphore 信号量
Semaphore 是一个控制访问多个共享资源的计数器. 当一个线程想要访问某个共享资源,首先,它必须获得 semaphore.如果 semaphore 的内部计数器的值大于 0,那么 semapho ...
- MongoDB - Introduction to MongoDB, Capped Collections
Overview Capped collections are fixed-size collections that support high-throughput operations that ...
- Swift常量和变量以及命名规范
我们在上一章中介绍了如何使用Swift编写一个HelloWorld小程序,其中就用到了变量.常量和变量是构成表达式的重要组成部分.常量在声明和初始化变量时,在标识符的前面加上关键字let,就可以把该变 ...
- 高性能CSS(二)
避免CSS表达式 CSS表达式是动态设置CSS属性的强大(但危险)方法.Internet Explorer从第5个版本开始支持CSS表达式.下面的例子中,使用CSS表达式可以实现隔一个小时切换一次背景 ...
- VS2013编译WEBKIT
0,安装VS2013:DXSDK_Jun10.exe:QuickTimeSDK.exe 1,WebKit-r174650.tar.bz2 以管理员解压(非管理员解压最后几下总是报错) 2,设置环境变量 ...
- Z-Stack ZMain学习
[注:本文源自博客园http://www.cnblogs.com/cherishui/,为尊重劳动者成果,如需转载请保留此行] 在TI已有的Z-Stack的工程下面,打开已有的demo文件,通过分析不 ...
- debian 学习记录-1 -安装
之前装ubuntu12. 后来没有继续用,图形界面很不错,没有继续学习原因很多: · 没有基础知识支持(拷贝文件都是用鼠标拖动的) · 图形界面很好,导致没有使用命令行,安装驱动什么的都是靠鼠标点击 ...