1491: [NOI2007]社交网络
Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1159 Solved: 660
[Submit][Status][Discuss]
Description
Input
Output
输出文件包括n 行,每行一个实数,精确到小数点后3 位。第i 行的实数表 示结点i 在社交网络中的重要程度。
Sample Input
4 4
1 2 1
2 3 1
3 4 1
4 1 1
1 2 1
2 3 1
3 4 1
4 1 1
Sample Output
1.000
1.000
1.000
1.000
1.000
1.000
1.000
HINT
为1
Source
题解:郑爷讲过,最简单的最短路计数了吧。
1 /*============================================================================= 2 * 3 * Author: Crt_16 4 * 5 * Last modified: 2015-08-26 19:10 6 * 7 * Category:图论 最短路 8 * 9 /*=============================================================================*/ 10 11 #include<iostream> 12 #include<cstdio> 13 #include<cmath> 14 #include<algorithm> 15 #include<stack> 16 #include<queue> 17 #include<cstring> 18 #define pau putchar(' ') 19 #define ent puts(""); 20 #define mse(a,b) memset(a,b,sizeof(a)) 21 #define ren(x) for(ted*e=fch[x];e;e=e->nxt) 22 #define rep(i,s,t) for(int i=s,__=t;i<=__;i++) 23 #define dwn(i,s,t) for(int i=s,__=t;i>=__;i--) 24 using namespace std; 25 const int maxn=100+10,maxm=4500+10,inf=1e9; 26 int d[maxn][maxn],n,m;long long f[maxn][maxn]; 27 inline int read(){ 28 int x=0;bool sig=true;char ch=getchar(); 29 for(;!isdigit(ch);ch=getchar())if(ch=='-')sig=false; 30 for(;isdigit(ch);ch=getchar())x=10*x+ch-'0';return sig?x:-x; 31 } 32 inline void write(int x){ 33 if(x==0){putchar('0');return;}if(x<0)putchar('-'),x=-x; 34 int len=0;static int buf[20];while(x)buf[len++]=x%10,x/=10; 35 for(int i=len-1;i>=0;i--)putchar(buf[i]+'0');return; 36 } 37 int main(){ 38 n=read();m=read();int x,y; 39 rep(i,1,n)rep(j,1,n)d[i][j]=inf;rep(i,1,n)d[i][i]=0; 40 rep(i,1,m)x=read(),y=read(),d[x][y]=d[y][x]=read(); 41 rep(i,1,n)rep(j,1,n)f[i][j]=1; 42 rep(k,1,n)rep(i,1,n)rep(j,1,n)if((i^j)&&(j^k)&&(k^i)){ 43 if(d[i][j]>d[i][k]+d[k][j]){ 44 d[i][j]=d[i][k]+d[k][j]; 45 f[i][j]=f[i][k]*f[k][j]; 46 } 47 else if(d[i][j]==d[i][k]+d[k][j])f[i][j]+=f[i][k]*f[k][j]; 48 } 49 double ans[maxn];mse(ans,0.0); 50 rep(k,1,n)rep(i,1,n)rep(j,1,n)if((i^j)&&(j^k)&&(k^i)&&(d[i][j]==d[i][k]+d[k][j])){ 51 ans[k]+=(double)f[i][k]*(double)f[k][j]/(double)f[i][j]; 52 }rep(i,1,n)printf("%.3lf ",ans[i]); 53 54 return 0; 55 }