标签:图
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int d[311][311], n, m, par[311], rank[311], team[311];
void get_team(void) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) d[i][j] = 0;
else d[i][j] = 0x3fffff;
}
}
for (int i = 0; i < m; i++) {
int x;
scanf("%d", &x);
for (int j = 0; j < x; j++) {
scanf("%d", &team[j]);
}
for (int j = 0; j < x; j++) {
for (int k = j + 1; k < x; k++) {
if (team[k] == team[j]) continue;
d[team[k] - 1][team[j] - 1] = 1;
d[team[j] - 1][team[k] - 1] = 1;
}
}
}
}
void Floyd_Warshall(void) {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
for(int k = 0; k < n; k++) d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}
int average_max(void) {
int max = 0x3fffff;
for (int i = 0; i < n; i++) {
int temp = 0;
for (int j = 0; j < n; j++) {
temp += d[i][j];
}
if(temp < max) swap(max, temp);
}
return max * 100 / (n - 1);
}
int main(void) {
while (~scanf("%d%d", &n, &m)) {
get_team();
Floyd_Warshall();
printf("%d\n",(int)average_max());
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:图
原文地址:http://blog.csdn.net/jibancanyang/article/details/47000597