无向图求割点和连通块。

 /* POJ2117 */
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std; #define MAXN 10005 vector<int> vc[MAXN];
int low[MAXN], pre[MAXN];
int n, m;
int dfs_clock, ans, link; void init() {
int i; for (i=; i<n; ++i)
vc[i].clear(); memset(pre, , sizeof(int)*n);
dfs_clock = ans = link = ;
} void tarjan(int u, int fa) {
int i, j, k, v;
int child = ;
int cnt = ; pre[u] = low[u] = ++dfs_clock;
for (i=; i<vc[u].size(); ++i) {
v = vc[u][i];
if (!pre[v]) {
++child;
tarjan(v, u);
low[u] = min(low[u], low[v]);
if (low[v] >= pre[u]) {
++cnt;
}
} else if (pre[v]<pre[u] && v!=fa){
low[u] = min(low[u], pre[v]);
}
}
if (fa == -) {
if (child > )
ans = max(ans, child-);
} else {
ans = max(ans, cnt);
}
} int main() {
int i, j, k; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif while (scanf("%d %d",&n,&m)!=EOF && (n||m)) {
if (m == ) {
printf("%d\n", n-);
continue;
}
init();
for (i=; i<m; ++i) {
scanf("%d %d", &j, &k);
vc[j].push_back(k);
vc[k].push_back(j);
}
for (i=; i<n; ++i) {
if (!pre[i]) {
++link;
tarjan(i, -);
}
}
printf("%d\n", ans+link);
} return ;
}

最新文章

  1. web前端开发中常用的尺寸和位置
  2. 读取手机上所有应用程序并显示(APP)
  3. Java并发包中CountDownLatch的工作原理、使用示例
  4. about eclipse
  5. Tuning SQL via case when statement
  6. C/C++程序员面试易错题
  7. UVA 624 (0 1背包 + 打印路径)
  8. shell中的IFS详解
  9. Bye,IE!服务互联网20年IE终于要退役了
  10. Linux:系统的基本优化
  11. php __set()和__get()函数
  12. [noip 2015]运输计划 [LCA][树链剖分]
  13. Java的static关键字
  14. Maven项目构建管理
  15. python2.7添加注释后,代码无法保存
  16. Docker的网络类型和固定IP设置
  17. 使用Flex4画图形:圆、矩形、线
  18. Pairs of Songs With Total Durations Divisible by 60 LT1010
  19. sip (gb28181)信令交互-视频点播与回播
  20. ngx_lua_API 指令详解(四)ngx.exec指令

热门文章

  1. html 之前学习响应式的笔记
  2. [分词] C#SegList分词辅助类,帮助类 (转载)
  3. Developing iOS8 Apps with Swift——iOS8概览
  4. java实现时间的比较
  5. Spring Security Encryption三种加密方式
  6. 一段C++代码想到的问题
  7. nullptr和NULL 区别
  8. ThinkPHP 中使用 PHPMailer 发送邮件 支持163和QQ邮箱等
  9. angular 跳转页面时传参
  10. JavaScript学习总结【5】、JS DOM