#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn = 1e4+10;
int dis[maxn][maxn];
int n, m;
void floyd(){
for(int k = 1; k <= n; k++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(dis[i][j] > dis[i][k]+dis[k][j]){
dis[i][j] = dis[i][k] + dis[k][j];
}
}
}
}
}
int main(){
int u, v;
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(i==j) dis[i][j] = 0;
else dis[i][j] = INF;
}
}
for(int i = 0; i < m; i++){
scanf("%d%d",&u,&v);
dis[u][v] = dis[v][u] = 1;
}
floyd();
//判断连通性
int flag = 1;
for(int i = 1; i <= n; i++){
if(dis[1][i] == INF){
flag = 0;
break;
}
}
int k, x;
scanf("%d",&k);
while(k--){
scanf("%d",&x);
double sum = 0, avg = 0;
for(int i = 1; i <= n; i++){
if(dis[x][i] < INF) sum += dis[x][i];
}
avg = (n-1)*1.0/sum;
//cout << sum << endl;
if(flag) printf("Cc(%d)=%.2lf\n",x, avg);
else printf("Cc(%d)=0.00\n",x);
}
//system("pause");
return 0;
}
仅供参考 切勿抄袭
hang hang hang !!!