BZOJ1491 [NOI2007] Social network

Source: Internet
Author: User

Descriptionin the study of social networks (socialnetwork), we often use the concept of graph theory to explain some social phenomena. Let's look at a question like this. there are n individuals in a social circle, and there are different levels of relationships between people. We are going to map this relationship network to an n-node graph,two different people, if they know each other, connect a non-aligned edge between their corresponding nodes, and attach a positive value c,c the smaller, representing two peoplethe more closely the relationship between them. We can use the shortest distance between the corresponding nodes to measure the close relationship between two people s and T, and noticeThe other nodes on the path provide some convenience for the link between s and T, that is, the links between S and T are of some importance. We can passThe number of shortest paths through a node V is counted to measure how important the node is in a social network. Considering that there may be between two nodes A and B.more than one shortest path. The definition of the importance of our modifications is as follows: To make the cs,t represent different shortest-circuiting numbers from S to T, Cs,t (v) represents a V from SThe number of short-circuiting to T;is the degree of importance of node V in social networks. To make sense for I (v) and Cs,t (v), we stipulate that the social networks that need to be processed are connected undirected graphs, which is the shortest path with a finite length between any two nodes. Now give a weighted graph describing social networks, and ask you to find out everythe degree of importance of a node. InputEnter the first line with two integers n and m, representing the number of nodes and non-forward edges in the social network. In the no-map, we numbered all the nodes from 1 to N.. Next m line, each line with three integer a,b,c describes a connection node A and B, a weight of C, no forward edge. Note that there is a maximum of two nodes between anya non-forward edge is connected, and no self-loops appear in the graph (i.e., two endpoints that do not have a non-forward edge are the same node). n≤100;m≤4500, the weight of any one side C is a positive integer, satisfies: 1≤c≤1000. All data are guaranteed to have undirected graphs communicated, and any two nodes betweenthe shortest path number does not exceed 10^10Output

The output includes n rows, one real number per line, and 3 digits after the decimal point. The real number on line I indicates how important node I is in social networks.

Sample Input4 4
1 2 1
2 3 1
3 4 1
4 1 1Sample Output1.000
1.000
1.000
1.000HINT

Social networks as shown.

for the 1th junction, only the shortest path between the 2nd and 4th nodes and the 4th to 2nd Junction is the number 1th junction, and the 2nd Junction and the 4th junction.

the shortest path between the points is 2. Thus, by definition, the importance of the number 1th node is calculated as 1/2 + 1/2 = 1. Because of the symmetry of graphs, other

the importance of three nodes is also 1. Positive solution: FloydProblem Solving Report:n<=100, how to mess up how to mess up ... Floyd to find the shortest point between two points, by the way statistics how many different shortest. then the second time to do, according to the definition of the significance of each node ans[i], if the K exists I to J of the shortest, then ans[k] need to add this contribution, by the way statistics on it.
1 //It's made by jump~2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <algorithm>8#include <ctime>9#include <vector>Ten#include <queue> One#include <map> A#include <Set> - #ifdef WIN32 - #defineOT "%i64d" the #else - #defineOT "%lld" - #endif - using namespacestd; +typedefLong LongLL; - Const intMAXN = Max; + intn,m; A intW[MAXN][MAXN]; at DoubleNUM[MAXN][MAXN]; - DoubleANS[MAXN]; -  -InlineintGetint () - { -        intw=0, q=0; in        CharC=GetChar (); -         while((c<'0'|| C>'9') && c!='-') c=GetChar (); to        if(c=='-') q=1, c=GetChar (); +         while(c>='0'&& c<='9') w=w*Ten+c-'0', c=GetChar (); -        returnQ? -w:w; the } *  $InlinevoidWork () {Panax NotoginsengN=getint (); M=getint ();intx, y, z -Memset (W,127/3,sizeof(w)); the      for(intI=1; i<=m;i++) { +X=getint (); Y=getint (); z=getint (); AW[x][y]=w[y][x]=z; num[x][y]=num[y][x]=1; the     } +      for(intk=1; k<=n;k++) -      for(intI=1; i<=n;i++)  $         if(i!=k) $          for(intj=1; j<=n;j++) -             if(J!=k && j!=i) { -             if(w[i][j]>w[i][k]+W[k][j]) { thew[i][j]=w[i][k]+W[k][j]; -num[i][j]=num[i][k]*Num[k][j];Wuyi             } the             Else if(W[i][j]==w[i][k]+w[k][j]) num[i][j]+=num[i][k]*Num[k][j]; -             } Wu  -      for(intk=1; k<=n;k++)  About      for(intI=1; i<=n;i++)if(i!=k) $          for(intj=1; j<=n;j++) -         if(J!=k && j!=i) { -             if(W[i][j]==w[i][k]+w[k][j]) ans[k]+= ((Num[i][k]*num[k][j])/num[i][j]);//contributing to the importance of the relay point as this pair of points -         } A      for(intI=1; i<=n;i++) printf ("%.3lf\n", Ans[i]); + } the  - intMain () $ { the Work (); the   return 0; the}

BZOJ1491 [NOI2007] Social network

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.