目录
题目:
输入、输出格式:
代码:
运行结果:
题目:
输入、输出格式:
代码:
#include<iostream>
#include<algorithm>
using namespace std;
int g[10005][10005];
float n, k;
typedef struct node
{
int data;
int w = 0;
}node;
void warshall()//传递闭包
{
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
{
if (g[i][k] && g[k][j])//连通
{
if (i == j)
continue;
if (g[i][j] == 0 || g[i][j] > g[i][k] + g[k][j])/没有直接连通或者新通路距离小于之前通路
g[i][j] = g[i][k] + g[k][j];
}
}
}
bool cmp(node a, node b)
{
return a.w < b.w;
}
int main()
{
cin >> n >> k;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
g[i][j] = 0;
for (int i = 0; i < k; i++)
{
int v1, v2;
cin >> v1 >> v2;
g[v1][v2] = 1;
g[v2][v1] = 1;
}
warshall();
/*for (int i = 1; i <= n; i++)//输出邻接矩阵
{
for (int j = 1; j <= n; j++)
cout << g[i][j] << " ";
cout << endl;
}*/
float ans[10005] ;
for (int i = 1; i <= n; i++)
{
ans[i] = 0;
for (int j = 1; j <= n; j++)
{
if (i == j)
ans[i]++;
if (g[i][j]>0 && g[i][j] <= 6)//符合条件
ans[i]++;
}
}
for (int i = 1; i <= n; i++)
printf("%d:% .2f%%\n", i, ans[i] / n * 100);
}