PAT (Advanced Level) Practise 1076 Forwards on Weibo (30)
来源:互联网 发布:比特币挖矿用什么软件 编辑:程序博客网 时间:2024/05/26 22:57
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
对于要找的每个点进行一次广搜,求出距离小于L的有几个就好了。
#include<cstdio>#include<stack>#include<cstring>#include<string>#include<vector>#include<queue>#include<iostream>#include<algorithm>#include<functional>using namespace std;const int INF = 0x7FFFFFFF;const int maxn = 1e3 + 15;int dis[maxn];vector<int> t[maxn];int n, m, x, y;int main(){scanf("%d%d", &n, &m);for (int i = 1; i <= n; i++){scanf("%d", &x);while (x--){scanf("%d", &y);t[y].push_back(i);}}scanf("%d", &x);while (x--){scanf("%d", &y);for (int i = 1; i <= n; i++) dis[i] = 0x7FFFFFFF;int ans = dis[y] = 0;queue<int> p; p.push(y);while (!p.empty()){int q = p.front();p.pop();if (dis[q] <= m) ans++; else break;for (int i = 0; i < t[q].size(); i++){if (dis[t[q][i]]>dis[q] + 1){dis[t[q][i]] = dis[q] + 1;p.push(t[q][i]);}}}printf("%d\n", ans - 1);}return 0;}
- PAT (Advanced Level) Practise 1076 Forwards on Weibo (30)
- PAT (Advanced Level) Practise 1076 Forwards on Weibo (30)
- 1076. Forwards on Weibo (30)【树+搜索】——PAT (Advanced Level) Practise
- Pat(Advanced Level)Practice--1076(Forwards on Weibo)
- PAT Advanced Level 1076. Forwards on Weibo (30)
- 【PAT】【Advanced Level】1076. Forwards on Weibo (30)
- PAT (Advanced) 1076. Forwards on Weibo (30)
- PAT (Advanced Level) 1076. Forwards on Weibo (30) 微博转发 BFS
- PAT 1076-Forwards on Weibo (30)
- PAT-Forwards on Weibo
- PAT 1076 Forwards on Weibo BFS
- PAT A 1076. Forwards on Weibo (30)
- PAT-1076. Forwards on Weibo (30)
- pat 1076. Forwards on Weibo (30)
- PAT 1076. Forwards on Weibo (30)
- PAT 1076. Forwards on Weibo (30)
- PAT 1076. Forwards on Weibo (30)
- 【PAT】 1076. Forwards on Weibo (30)
- 有向路径检查
- C语言中putchar()函数的使用
- 杵臼关节(发)
- C:\WINDOWS\system32\drivers\etc\hosts 文件有什么作用
- 集合元素的删除
- PAT (Advanced Level) Practise 1076 Forwards on Weibo (30)
- Maven依赖范围
- 经典的Java基础面试题
- 星号图
- PHP异常处理方法
- hdu 3974 Assign the task(线段树+将树映射到区间)
- 顺序栈
- Action Bar(title文字大小问题 基本运用)
- OC2-1