#include <iostream>
#include <stdlib.h>
using namespace std;
int weight[10001][10001];
int n, m;
#define N 10000
void init()
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (i == j)
{
weight[i][j] = 0;
}
else
weight[i][j] = N;
}
}
}
void floyed()
{
for (int k = 1; k <= n; k++)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (weight[i][j] > weight[i][k] + weight[k][j])
{
weight[i][j] = weight[i][k] + weight[k][j];
}
}
}
}
}
int main()
{
cin >> n >> m;
init();
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
weight[a][b] = weight[b][a] = 1;
}
floyed();
int f;
f=0;
for (int j = 1; j <= n; j++)
{
if (weight[1][j] == N)
{
f = 1;
break;
}
}
int k;
cin>>k;
for (int m = 0; m <k; m++)
{
int num;
cin >> num;
double averge = 0;
for (int j = 1; j <= n; j++)
{
if (weight[num][j] != N)
{
averge = averge + weight[num][j];
}
}
averge = 1.0 / (averge * 1.0 / (n - 1));
if (f == 1)
{
printf("Cc(%d)=%.2f\n", num, 0);
}
else
{
printf("Cc(%d)=%.2f\n", num, averge);
}
}
return 0;
}
社交网络的节点计算(动态规划)
最新推荐文章于 2021-12-26 13:44:58 发布