#include<iostream>
#include<queue>
#include<cstdio>
using namespace std;
int s,t,n,m,last[10005],d[10005],k,cnt;
struct edge{
int v,w,next;
}e[200005];
void add(int u,int v){
e[++cnt].v=v;
e[cnt].w=1;
e[cnt].next=last[u];
last[u]=cnt;
}
struct heapnode{
int u,d;
bool operator<(const heapnode & a)const{
return d>a.d;}
};
priority_queue<heapnode>q;
void dijkstra()
{
for(int i=1;i<=n;i++)
d[i]=0x3f3f3f;
d[s]=0;
q.push((heapnode){s,0});
while(!q.empty())
{
heapnode x=q.top();q.pop();
int u=x.u;
if(d[u]!=x.d) continue;
for(int i=last[u];i;i=e[i].next)
{
int v=e[i].v;
if(d[v]>d[u]+e[i].w){
d[v]=d[u]+e[i].w;
q.push((heapnode){v,d[v]});
}
}
}
}
int main()
{
cin>>n>>m;
for(int i=1,u,v;i<=m;i++)
{
scanf("%d%d",&u,&v);
add(u,v);
add(v,u);
}
cin>>k;
for(int i=1;i<=k;i++)
{
cin>>s;
dijkstra();
long long ans=0;
for(int j=1;j<=n;j++)
{
ans+=d[j];
if(d[j]==0x3f3f3f)
{
ans=0;
break;
}
}
double ac=(double)ans/(n-1);
ac=ans?1/ac:0;
printf("Cc(%d)=%.2lf\n",s,ac);
}
return 0;
}
7-10 社交网络图中结点的“重要性”计算
最新推荐文章于 2023-11-12 15:29:24 发布