#include <stdio.h>
#include <string.h>
int node[25][25];
int rear[25], visit[25];
int edges[25][25];
int max;
void dfs(int n, int lenght)
{
int i;
if (lenght > max)
max = lenght;
for (i = 0; i < rear[n]; i++) {
if (!edges[n][node[n][i]] && !edges[node[n][i]][n]) {
edges[n][node[n][i]] = 1;
edges[node[n][i]][n] = 1;
dfs(node[n][i], lenght+1);
edges[n][node[n][i]] = 0;
edges[node[n][i]][n] = 0;
}
}
}
int main()
{
int n, m;
int i;
int a, b;
while (scanf("%d%d", &n, &m), n||m) {
memset(rear, 0, sizeof(rear));
max = 0;
for (i = 0; i < m; i++) {
scanf("%d%d", &a, &b);
node[a][rear[a]++] = b;
node[b][rear[b]++] = a;
}
for (i = 0; i < n; i++) {
dfs(i, 0);
}
printf("%d\n", max);
}
return 0;
}
POJ-2258
最新推荐文章于 2020-09-02 09:14:18 发布