1076. Forwards on Weibo (30)
来源:互联网 发布:js中的classname啥意思 编辑:程序博客网 时间:2024/05/22 02:08
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 33 2 3 402 5 62 3 12 3 41 41 52 2 6Sample Output:
45
求从一个结点开始层层向外在给定的层数范围内有多少结点
dfs会破坏路径,采用bfs
#include<stdio.h>#include<vector>#include<queue>using namespace std;vector<int>adj[1010];int n,level,cou;int visit[1010],layer[1010];void init(){int i;for(i=1;i<=n;i++){visit[i]=0;}}void bfs(int s){visit[s]=1;layer[s]=0;queue<int>q;q.push(s);while(!q.empty()){int head=q.front();q.pop();//visit[head]=1;//不能在这里标记!! int i;for(i=0;i<adj[head].size();i++){int next=adj[head][i];if(visit[next]==0){visit[next]=1;layer[next]=layer[head]+1;if(layer[next]<=level){cou++;}else{break;}q.push(next);}}}}int main(){int i,j,k,user;scanf("%d %d",&n,&level);for(i=1;i<=n;i++){scanf("%d",&k);for(j=0;j<k;j++){scanf("%d",&user);adj[user].push_back(i);}}scanf("%d",&k);for(i=0;i<k;i++){scanf("%d",&user);cou=0;init();bfs(user);printf("%d\n",cou);}}
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)
- C语言中函数参数的入栈顺序
- java RSA公私钥与其base64编码之间的转换
- 天空之城 欢乐颂
- Python与风水 的‘’南北通透‘’住宅与‘’南北” 向住宅的均价数据分析
- pdf转换神器,功能全面高质量解决pdf转换问题
- 1076. Forwards on Weibo (30)
- 发送短信工具类(亿美短信平台接口)
- js中的加、减、乘、除(适用于所有场景)
- 《笨办法学python》加分习题29——我的答案
- POJ 2503 Babelfish(字典树Trie)
- Butter Knife 配置及使用入门详解
- ROS人脸检测追踪
- 工作流相关的表及其分类
- 工作流