poj 3895 Cycles of Lanes(DFS找最大环)
来源:互联网 发布:12864与单片机连接图 编辑:程序博客网 时间:2024/06/05 19:42
http://poj.org/problem?id=3895
题目大意:
一个无向图,找出包含顶点个数的环,输出最大顶点个数;
思路:
简单搜索
#include<iostream>#include<vector>#define N 5000using namespace std;int vis[N],n,m;int Max;vector <int> graph[N];//vector存储相连接的点void DFS(int v,int d){ vis[v]=d; int size=graph[v].size(); for(int i=0;i<size;i++) { if(!vis[graph[v][i]])// DFS(graph[v][i],d+1); else { if(vis[v]-vis[graph[v][i]]+1>Max) Max=vis[v]-vis[graph[v][i]]+1; } }}int main(){ int t; scanf("%d",&t); while(t--) { int s,e; scanf("%d%d",&n,&m); for(int i=0;i<=n;i++) graph[i].clear(); for(int j=0;j<m;j++) { scanf("%d%d",&s,&e); graph[s].push_back(e); graph[e].push_back(s); //双向建图 } Max=0; memset(vis,0,sizeof(vis)); for(int k=1;k<=n;k++) { if(!vis[k]) DFS(k,1);//DFS找环, } if(Max<=2)//Max<=2即不存在环 Max=0; printf("%d\n",Max); } return 0;}
- poj 3895 Cycles of Lanes(DFS找最大环)
- poj-3895-Cycles of Lanes 简单DFS
- POJ 3895 Cycles of Lanes(DFS)
- POJ 3895 Cycles of Lanes (dfs)
- POJ 3895 Cycles of Lanes(DFS)
- POJ 3895 Cycles of Lanes
- POJ 3895 Cycles of Lanes
- POJ 3895 Cycles of Lanes
- POJ 3895 Cycles of Lanes
- POJ 3895 Cycles of Lanes(dfs+模拟)
- poj 3895 Cycles of Lanes 修改tarjan算法求图中最大环
- POJ3895 Cycles of Lanes,DFS
- poj 3895.Cycles of Lanes
- POJ 3895 Cycles of Lanes 已被翻译
- poj3895 Cycles of Lanes
- poj3895 Cycles of Lanes
- poj3895Cycles of Lanes(dfs)
- poj 3895 dfs找图中最大环
- 链表常见面试题
- cudaMallocPitch的使用
- UNIX网络编程——原始套接字(dos攻击)
- 宏杰文件夹加密V2878【永久免费的文件加密软件】
- LA 4329 - Ping pong 树状数组(Fenwick树)
- poj 3895 Cycles of Lanes(DFS找最大环)
- ubuntu下rpm的安装 pdf中文显示
- Ubuntu 13.04 安装
- Maya: 菜单 曲面 >旋转
- QT显示图片
- OSWorkFlow深入浅出(7)---Step3详解
- html 元素
- 通过邮件发送验证码来修改密码
- 中文版Chrome浏览器不支持12px以下字体的解决方案