当前位置:网站首页>1076 Forwards on Weibo
1076 Forwards on Weibo
2022-07-01 04:49:00 【Study hard 867】
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 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 trigger, 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
5The main idea of the topic : Forward wechat , Fans forward , Fans' fans can also forward , Fans who reach a certain delivery level will not forward , Ask how many people can pass at most .
Ideas : The relationship between fans can be seen as the distance between cities , Find the minimum distance between each city , Then, if the minimum distance is less than the corresponding number of layers, the corresponding number of people can be counted , The box floyd Algorithm , The only thing to note is that the format of the input is the person he cares about , Not the people who care about him .
#include <bits/stdc++.h>
using namespace std;
#define inf 9999999
int main(){
int n,m;
scanf("%d%d",&n,&m);
int i;
int a[n+1][n+1];
fill(a[0],a[0]+(n+1)*(n+1),inf);// Initialization operation
for(i=1;i<=n;i++)a[i][i]=0;
int num,j;
for(i=1;i<=n;i++){
scanf("%d",&num);
for(j=0;j<num;j++){// Regulations a[i][j] by i Yes j Contribution of nodes .
int val;
scanf("%d",&val);
a[i][val]=1;
}
}
int k;
for(i=1;i<=n;i++){// Find the nearest relationship of each intermediary
for(j=1;j<=n;j++){
for(k=1;k<=n;k++){
if(a[j][k]>a[j][i]+a[i][k]){
a[j][k]=a[j][i]+a[i][k];
}
}
}
}
int cha;
scanf("%d",&cha);
int nums[n+1];
memset(nums,0,sizeof(nums));
for(i=1;i<=n;i++){// Enumerate the contribution of each node to this point , That is, the number of objects he follows and forwards
for(j=1;j<=n;j++){
if(j!=i&&a[i][j]<=m)nums[j]++;
}
}
for(i=0;i<cha;i++){
scanf("%d",&num);
printf("%d\n",nums[num]);
}
system("pause");
}边栏推荐
- 分布式锁的实现
- 【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
- LeetCode_53(最大子数组和)
- How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
- Talk about testdeploy
- Research on medical knowledge atlas question answering system (I)
- Leecode question brushing record 1332 delete palindrome subsequence
- LeetCode522-最长特殊序列II-哈希表-字符串-双指针
- [hardware ten treasures catalogue] - reprinted from "hardware 100000 whys" (under continuous update ~ ~)
- LeetCode_ 53 (maximum subarray and)
猜你喜欢

常用的Transforms中的方法

Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor

Neural networks - use sequential to build neural networks

【硬十宝典】——1.【基础知识】电源的分类

STM32 photoresistor sensor & two channel AD acquisition

最长递增子序列及最优解、动物总重量问题

LeetCode1497-检查数组对是否可以被 k 整除-数组-哈希表-计数

Common methods in transforms

Pytorch convolution operation

The index is invalid
随机推荐
Basic exercise of test questions hexadecimal to decimal
点赞的云函数
无器械健身
LeetCode316-去除重复字母-栈-贪心-字符串
Why is Internet thinking not suitable for AI products?
STM32 光敏电阻传感器&两路AD采集
手动实现一个简单的栈
【暑期每日一题】洛谷 P3742 umi的函数
神经网络-最大池化的使用
解决:拖动xib控件到代码文件中,报错setValue:forUndefinedKey:this class is not key value coding-compliant for the key
[daily question in summer] Luogu p7222 [rc-04] informatics competition
LM small programmable controller software (based on CoDeSys) note 20: PLC controls stepping motor through driver
I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own
数据加载及预处理
技术分享| 融合调度中的广播功能设计
Leecode question brushing record 1310 subarray XOR query
神经网络-卷积层
RuntimeError: “max_pool2d“ not implemented for ‘Long‘
RuntimeError: mean(): input dtype should be either floating point or complex dtypes. Got Long instead
LeetCode_53(最大子数组和)