当前位置:网站首页>Six dimensional space BFS
Six dimensional space BFS
2022-06-29 10:13:00 【Momo 623】
“ Six degrees of space ” Theory is also called “ Six degrees apart (Six Degrees of Separation)” theory . This theory can be explained as :“ There will be no more than six people between you and any stranger , in other words , You can meet any stranger by five people at most .” Pictured 1 Shown .

“ Six degrees of space ” Although the theory is widely accepted , And it's getting more and more applications . But for decades , Trying to test this theory has always been the goal of many sociologists . But for historical reasons , Such research has too much limitation and difficulty . With modern people's contact mainly depends on the telephone 、 SMS 、 Wechat and instant messaging on the Internet , The first-hand data that can reflect social network relationships has gradually made “ Six degrees of space ” It is possible to test the theory .
If I give you a social network diagram , Please calculate each node according to “ Six degrees of space ” The percentage of theoretical nodes in the total number of nodes .
Input format :
Enter the first 1 Line gives two positive integers , Respectively represent the nodes of social network graph N(1<N≤10
3
, It means the number of people )、 Number of edges M(≤33×N, It means the social relation coefficient ). And then M Row correspondence M side , Each line gives a pair of positive integers , They are the numbers of the two nodes directly connected by the edge ( Node slave 1 To N Number ).
Output format :
For each node, the distance between the output and the node is not more than 6 The percentage of the number of nodes in the total number of nodes , Accurate to the decimal point 2 position . One line per nodule , The format is “ Node number :( Space ) percentage %”.
sample input :
10 9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
sample output :
1: 70.00%
2: 80.00%
3: 90.00%
4: 100.00%
5: 100.00%
6: 100.00%
7: 100.00%
8: 90.00%
9: 80.00%
10: 70.00%
————————————————————————————
The time limit is very long
There is no need to consider the time complexity
Thinking is also more violent :
Traverse each point ,N Time bfs, however bfs Only a limited number of times , the reason being that 6 Limit of degree space ;
Not more than each time 6 There are a few of them
Then go back
#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
const int n = 1e3 + 10;
vector<int> v[n];
int N;
double bfs(int k)
{
queue<pair<int, int>> q;
int dp[n] = {
0};
q.push({
k, 0});
dp[k] = 1;
int cnt = 0;
while (!q.empty())
{
auto x = q.front();
q.pop();
if (x.second >= 7)
break;
cnt++;
for (auto &e : v[x.first])
if (!dp[e])
{
dp[e] = 1;
q.push({
e, x.second + 1});
}
}
return 1.0 * cnt / N * 100;
}
int main()
{
int M, x, y;
cin >> N >> M;
while (M--)
{
scanf("%d%d", &x, &y);
v[x].push_back(y);
v[y].push_back(x);
}
for (int i = 1; i <= N; i++)
{
printf("%d: %.2f%%\n", i, bfs(i));
}
return 0;
}
边栏推荐
- A method of creating easy to manage and maintain thread by C language
- EDA and VHDL question bank
- F5 BIG-IP iControl REST命令执行(CVE-2022-1388)
- JVM之 MinorGC、 MajorGC、 FullGC、
- Codeforces Round #645 (Div. 2)
- Codeforces Round #659 (Div. 2)
- Pipeline details of IPC (interprocess communication)
- HDU 6778 Car (分组枚举-->状压 dp)
- Application of keil5 integrated development environment for single chip microcomputer
- 同花顺炒股软件可靠吗,安全吗?
猜你喜欢

Nacos registry cluster

Flutter 基础组件之 Image

自定义控件之侧滑关闭 Activity 控件

JVM之对象的内存布局

Rikka with Cake(线段树+线段树)

阿里云防火墙配置,多种设置方式(iptables和fireward)

Constructing SQL statements by sprintf() function in C language

JVM之方法的绑定机制

Perfect binary tree, complete binary tree, perfect binary tree

Cisco ASA、FTD和HyperFlex HX的漏洞分析复现
随机推荐
Wandering --- 最后的编程挑战
2019.10.20训练总结
leetcode MYSQL数据库题目180
2019.11.3学习总结
Alibaba cloud firewall configuration, multiple settings (iptables and firewall)
十六制计数器和流水灯
Container of the basic component of the flutter
Leetcode MySQL database topic 180
JNI.h说明
Codeforces - 1151b thinking
Leetcode MySQL database topic 176
GridView of basic component of shutter
520 钻石争霸赛 2021
2019.10.27训练总结
If I were in Beijing, where would it be better to open an account? In addition, is it safe to open an account online now?
JVM instructions for four call methods
任务调度器之Azkaban的使用
Minorgc, majorgc, fullgc
函数指针、函数指针数组、计算器+转移表等归纳总结
Dynamic linking of virtual machine stack of JVM