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