05-Figure 3. Six degree space (30)

Source: Internet
Author: User

05-Figure 3. Six degree space (30) time limit MS
Memory Limit 65536 KB
Code length limit 8000 B
Procedures for the award of questions Standard

The "six-degree space" theory is also called the "six-degree separation (Six Degrees of Separation)" theory. This theory can be described in layman's words: "You and any stranger will not be more than six people, that is, up to five people you can know any stranger." As shown in "6.4.


Figure 6.4 Six-degree space

Although the theory of "six-degree space" has been widely accepted, it is getting more and more applications. But for decades, trying to validate this theory has been a goal that many sociologists have sought to pursue. However, due to the historical reasons, such research has too much limitation and difficulty. With the modern person's contact mainly relies on the telephone, the text message, as well as the Internet instantaneous communication and so on the tool, can embody the social network relations the primary data already gradually makes the "six degree space" the theory verification becomes possible.

If you are given a social network diagram, calculate the percentage of nodes that correspond to the six-degree space theory for each node.

Input Format Description:

Enter line 1th to give two positive integers, representing the number of nodes in the social network graph N (1<n<=104, representing the number of people), the number of sides m (<=33*n, which represents the social relationship). The subsequent M-line corresponds to the M-bar, and each row gives a pair of positive integers, each of which is the number of the two nodes directly connected to the bar (the node is numbered from 1 to n).

Output Format Description:

The percentage of the total number of nodes that each node output is not more than 6 from the node, and is accurate to 2 digits after the decimal point. Each node outputs a row in the form "node number: (space) percent%".

Sample input and output:

serial number Enter output
1
10 91 22 33 44 55 66 77 88 99 10
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%
2
10-yi-yi"
1:70.00%2:80.00%3:80.00%4:80.00%5:80.00%6:80.00%7:80.00%8:70.00%9:20.00%10:20.00%
3
11 101, 98 1010 
1:100.00%2:90.91%3:90.91%4:100.00%5:100.00%6:100.00%7:100.00%8:100.00%9:100.00%10:100.00%11:81.82%
4
2 11 2
1:100.00%2:100.00%



#include <stdio.h> #include <stdlib.h> #define MAX 10010struct vertex{int val;struct Vertex *next;}; int BFS (struct Vertex * * Vertex, int i, int n) {//breadth-First search 0int cnt = 0;//Record 6-tier traversal to the number of nodes int Visited[max] = {};int Queue[max] = {};int head = 0, rear = 0;visited[i] = 1;queue[rear++] = i;//will start element (0 layer) Enqueue int level = 0;//a layer of nodes are all queued, the end is then pressed into the level value to mark, the absolute value represents the number of layers Qu eue[rear++] = level;//No. 0 Tag queued while (Rear > head) {//queue non-empty int curr = queue[head++];//out if (Curr =-6) {//has traversed sixth layer, end break ;} if (curr <= 0) {//Tag node, indicates that a layer has been traversed, will mark the queue queue[rear++] =--level;continue;} ++cnt;//determines that the queue is not a tag node, the element is traversed +1struct Vertex *p = Vertex[curr];while (p) {//To queue the Cuur node's inaccessible adjacency point all if (!visited[p->val]) { Visited[p->val] = 1;queue[rear++] = p->val;} p = P->next;}} return CNT;} int main () {//freopen ("test.txt", "R", stdin), int n, m;scanf ("%d%d", &n, &m), struct vertex* Vertex[max] = {};for ( int i = 0; I < m; ++i) {//Component diagram, adjacency table implementation int V1, V2;SCANF ("%d%d", &v1, &v2), struct Vertex *p = (struct Vertex *) malloc (sizeof (struct Vertex));p->next = vertex[v1];//inserted into the list header P->val = V2;vertex[v1] = P;p = (struct Vertex *) malloc (sizeof (struct V Ertex));p->next = vertex[v2];p->val = v1;vertex[v2] = p;} for (int i = 1; I <= n; ++i) {int cnt = 0;CNT = BFS (vertex, I, N);p rintf ("%d:%.2f%%\n", I, 100.0 * cnt/n);} return 0;}


Title Link: http://www.patest.cn/contests/mooc-ds/05-%E5%9B%BE3

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

05-Figure 3. Six degree space (30)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.