Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- vector<int>graph[30];
- bool color[30][30];
- int node,edge;
- int dfs(int u)
- {
- int i,len = graph[u].size(),mx=0;
- for(i=0;i<len;i++)
- {
- if(!color[u][graph[u][i]])
- {
- color[u][graph[u][i]] = true;
- color[graph[u][i]][u] = true;
- mx = max(mx,1+dfs(graph[u][i]));
- color[u][graph[u][i]] = false;
- color[graph[u][i]][u] = false;
- }
- }
- return mx;
- }
- int main()
- {
- int ans,i,u,v,mx;
- while(scanf("%d%d",&node,&edge) &&node &&edge)
- {
- for(i=1;i<=edge;i++)
- {
- scanf("%d%d",&u,&v);
- graph[u].push_back(v);
- graph[v].push_back(u);
- }
- ans = 0;
- for(i=0;i<node;i++)
- {
- memset(color,false,sizeof(color));
- mx = dfs(i);
- ans = max(ans,mx);
- }
- printf("%d\n",ans);
- for(i=0;i<=node;i++)
- {
- graph[i].clear();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment