POJ-3895(vector数组+dfs)
来源:互联网 发布:人工智能的应用新闻 编辑:程序博客网 时间:2024/05/21 19:23
【题目描述】
求一个图中最大环的点个数
vector<int> g[4445];int visited[4445];int num[4445];int ans;void dfs(int v, int t){num[v] = t;visited[v] = 1;int l = g[v].size(), i;for (i = 0; i < l; ++i) {if (visited[g[v][i]]) {ans = MY_MAX(ans, num[v] - num[g[v][i]] + 1);} else {dfs(g[v][i], t + 1);}}}int main (){int t;scanf("%d", &t);while (t--) {ans = 0;memset(visited, 0, sizeof(visited));memset(num, 0, sizeof(num));int a, b, i, j, x, y;scanf("%d%d", &a, &b);for (i = 1; i <= a; ++i) g[i].clear();for (i = 0; i < b; ++i) {scanf("%d%d", &x, &y);g[x].push_back(y);g[y].push_back(x);}for (i = 1; i <= a; ++i) {if (visited[i] == 0) {dfs(i, 1);}}if (ans > 2) printf("%d\n", ans);else printf("0\n");} return 0;}
- POJ-3895(vector数组+dfs)
- poj 3321(dfs序&&树状数组)
- poj 3321 dfs + 树状数组
- poj 3321 dfs+树状数组
- POJ 3321 树状数组+DFS
- POJ 3321 APPLE TREE(树状数组+DFS)
- poj - 3321 - Apple Tree(dfs+树状数组)
- poj 3321 Apple Tree(dfs + 树状数组)
- POJ 3321 Apple Tree(树状数组+DFS)
- POJ Apple Tree (树状数组 + dfs序)
- POJ 3321 Apple Tree(dfs序 + 树状数组)
- POJ--3321 Apple Tree(树状数组+dfs(序列))
- POJ 3321 Apple Tree(DFS + 树状数组)
- POJ 3321 Ultra-QuickSort(树状数组+DFS序)
- POJ 3321 Apple Tree(dfs序 + 树状数组)
- poj 3321 Apple Tree(dfs染色+树状数组)
- poj 3321 Apple Tree(dfs标号+树状数组)
- poj 3321Apple Tree(树状数组+dfs映射)
- 使用memcpy进行数组元素移动
- 第十二周任务二
- java学习应该是阶段性成长的
- Android之Handler详解(一)
- Struts2整合Spring方法及原理
- POJ-3895(vector数组+dfs)
- Debug Assertion Failed!断言报错的解决
- 从今天起,开始重视写CSDN的技术博客!
- Xcode中文本编辑的一些快捷健
- ubuntu升级到12.04后mysql报错了
- JSP九大内置对象...
- Android之Handler详解(二)
- 读书笔记(5)
- “SELECT TOP N *”语句中“N”不能为变量的解决方案