#include <cstdio>
#include <cstdlib>
#include <iostream>
#define inf 0x3fffffff
using namespace std;
int a[101][101];
int n;
void func() {
int i, j, k, ans = 0;
for (k = 1; k <= n; k++)
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
if (a[i][j] == inf) {
printf("Secret.\n");
return;
}
ans = max(ans, a[i][j]);
}
}
printf("%d\n", ans);
}
int main(int argc, char** argv) {
int m, cas = 1;
int i, j;
scanf("%d %d", &n, &m);
while (n) {
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
a[i][j] = i == j ? 0 : inf;
while (m--) {
scanf("%d %d", &i, &j);
a[i][j] = a[j][i] = 1;
}
printf("Case %d:\n", cas++);
func();
scanf("%d %d", &n, &m);
}
return 0;
}
|