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个序号.输出每次询问的人发 ...
随机推荐
- Log4Net(三)之记录日志到数据库
前面两篇短文向大家介绍了如何使用log4net,以及如何将log4net记录到文本文件中.下面本文将向大家介绍如何将log4net记录到数据库中. 经过前面的介绍,我想大家对使用log4net的过程已 ...
- ORACLE时间函数(SYSDATE)深入理解
ORACLE时间函数(SYSDATE)深入理解 加法 select sysdate,add_months(sysdate,12) from dual; --加1年 select sysdate,add ...
- Activity保持关闭不销毁
activity按back键 消失但是不销毁的实现 重新定义finish()方法: @Override public void finish() { // TODO Auto-ge ...
- 使用CSS实现一个简单的幻灯片效果
方法一: 简单的CSS代码实现幻灯片效果 方法二: 使用CSS3 Animation来制作幻灯片 方法一: 简单的CSS代码实现幻灯片效果 话不多说,直接上代码 <!DOCTYPE html&g ...
- HTML+CSS 实现水流流动效果
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- Java Concurrency - wait & notify, 等待通知机制
生产者消费者问题是一个常见的多线程同步案例:一组生产者线程和一组消费者线程共享一个初始状态为空.大小为 N 的缓冲区.只有当缓冲区没满的时候,生产者才能把消息放入缓冲区,否则必须等待:只有缓冲区不空的 ...
- django 学习-3 模板变量
1.vim learn/home.html <!DOCTYPE html><html><head> <title>{{title}}< ...
- HDOJ2025查找最大元素
查找最大元素 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- Android 异常捕获
在用户使用APP时,如果APP毫无征兆的突然退出程序,又没有任何提示信息.我想这是一种最差劲的用户体验了吧,如果是我估计干脆就直接卸载APP了.因此,作为Android开发者对于这种情况的发生一定要有 ...
- Android之屏幕测试
MainActivity: package com.example.touchscreentest; import android.os.Bundle; import android.R.layout ...