1076. Forwards on Weibo (30)
来源:互联网 发布:centos7修改远程端口 编辑:程序博客网 时间:2024/06/07 22:53
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
今天我才知道我以前写的迪杰斯特拉算法是错的。
#include<iostream>#include<queue>#include<vector>#define M 1001using namespace std;vector <int > v[M];int vis[M];int len[M];int n,l,a,sum;const int INF=1<<29;typedef pair <int ,int> P;void dij(int s){ for (int i=0;i<=n;i++) { vis[i]=0; len[i]=INF; } len[s]=0; priority_queue<P,vector<P>,greater <P> > que; que.push({len[s],s}); while(que.size()) { P p=que.top(); que.pop(); int num=p.second; if (vis[num]==1)continue; vis[num]=1; for (int i=0;i<v[num].size();i++) { if (len[v[num][i]]>len[num]+1) { len[v[num][i]]=len[num]+1; que.push({len[v[num][i]],v[num][i]}); } } } int sum1=0; for (int i=1;i<=n;i++) { if (len[i]!=INF&&len[i]<=l&&s!=i) sum1++; } cout<<sum1<<endl;}int main(){ cin>>n>>l; for (int i=1;i<=n;i++) { cin>>sum; for (int j=0;j<sum;j++) { cin>>a; v[a].push_back(i); } } cin>>sum; for (int j=0;j<sum;j++) { cin>>a; dij(a); } return 0;}
- 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#内存泄漏实战
- MySQL防止重复插入唯一限制的数据 4种方法
- 数据结构之排序算法
- NYOJ-236
- 对数组进行冒泡排序,使用comparable接口实现
- 1076. Forwards on Weibo (30)
- UVA 1630 Folding——区间DP(记忆化搜索)
- AYIT2017暑假集训第三周周三赛 A
- SDNU 1519.lmh’s Function 找循环节
- 变量类型转换
- jvm类加载机制概述
- 【Java编程】面向对象基础
- 一分钟读懂低功耗蓝牙(BLE)MTU交换数据包
- 20-service之$watch