标签:targe efi ttl sizeof main stream net style space
思路:
对每个点都进行一次搜索,保存最长步数即可
代码:
#include<iostream> #include<cstdio> #include<cstring> #define MAXN 30 using namespace std; int n,m, G[MAXN][MAXN], vis[MAXN][MAXN], maxNum; void dfs(int u, int num) { for(int v=0; v<n; ++v) { if(G[u][v] && !vis[u][v]) { vis[u][v] = vis[v][u] = 1; dfs(v, num+1); vis[u][v] = vis[v][u] = 0; } } if(num > maxNum) maxNum = num; } int main() { int a,b; while(~scanf("%d %d", &n, &m)&&n&&m) { memset(G, 0, sizeof(G)); for(int i=0; i<m; ++i) { scanf("%d %d", &a, &b); G[a][b]++; G[b][a]++; } maxNum = 0; for(int i=0; i<n; ++i) { memset(vis, 0, sizeof(vis)); dfs(i, 0); } printf("%d\n",maxNum); } return 0; }
标签:targe efi ttl sizeof main stream net style space
原文地址:https://www.cnblogs.com/KasenBob/p/10888533.html