无向图求割点和连通块。

 /* 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 ;
}

【POJ】2117 Electricity的更多相关文章

  1. 【POJ】1704 Georgia and Bob(Staircase Nim)

    Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...

  2. 【POJ】1067 取石子游戏(博弈论)

    Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...

  3. 【BZOJ】【1986】【USACO 2004 Dec】/【POJ】【2373】划区灌溉

    DP/单调队列优化 首先不考虑奶牛的喜欢区间,dp方程当然是比较显然的:$ f[i]=min(f[k])+1,i-2*b \leq k \leq i-2*a $  当然这里的$i$和$k$都是偶数啦~ ...

  4. 【POJ】【2104】区间第K大

    可持久化线段树 可持久化线段树是一种神奇的数据结构,它跟我们原来常用的线段树不同,它每次更新是不更改原来数据的,而是新开节点,维护它的历史版本,实现“可持久化”.(当然视情况也会有需要修改的时候) 可 ...

  5. 【POJ】1222 EXTENDED LIGHTS OUT

    [算法]高斯消元 [题解] 高斯消元经典题型:异或方程组 poj 1222 高斯消元详解 异或相当于相加后mod2 异或方程组就是把加减消元全部改为异或. 异或性质:00 11为假,01 10为真.与 ...

  6. 【POJ】2892 Tunnel Warfare

    [算法]平衡树(treap) [题解]treap知识见数据结构 在POJ把语言从G++换成C++就过了……??? #include<cstdio> #include<algorith ...

  7. 【POJ】【1637】Sightseeing tour

    网络流/最大流 愚人节快乐XD 这题是给一个混合图(既有有向边又有无向边),让你判断是否有欧拉回路…… 我们知道如果一个[连通]图中每个节点都满足[入度=出度]那么就一定有欧拉回路…… 那么每条边都可 ...

  8. 【poj】1001

    [题目] ExponentiationTime Limit: 500MS Memory Limit: 10000KTotal Submissions: 123707 Accepted: 30202De ...

  9. 【POJ】3070 Fibonacci

    [算法]矩阵快速幂 [题解] 根据f[n]=f[n-1]+f[n-2],可以构造递推矩阵: $$\begin{vmatrix}1 & 1\\ 1 & 0\end{vmatrix} \t ...

随机推荐

  1. 在用VS2010连接oracle数据库时ORA-12504错误

    在用VS2010连接oracle数据库时,可能会出现: ORA-12504: TNS: 监听程序在 CONNECT_DATA 中未获得 SERVICE_NAME 只需在web.config文件Data ...

  2. svn出错问题(用户名密码有修改以及资源url改变时)

    用eclipse 同步SVN服务器宛然无法访问了: org.tigris.subversion.javahl.ClientException: RA layer request failed svn: ...

  3. mvc5 + ef6 + autofac搭建项目(repository+uow)(二)

    续上篇: DBContext 在上篇 图一类库根目录创建的 DbContextBase /// <summary> /// 数据库上下文基类 /// </summary> // ...

  4. “jni.h”: No such file or directory

    VS2010解决方案: 进入 “包含目录“ 方式: 右键项目属性页-> 配置属性->VC++目录->包含目录 在”包含目录“中编辑 添加以下路径: C:\Program Files\ ...

  5. Play - js/css concatenation & minify

    1. Css We’ll use LESS CSS, all less sources are defined in the app/assets, and they will be compiled ...

  6. 6 关于 Oracle NULL栏位和PL./SQL执行实验

    今日有针对NULL值有了相关实验. 对NULL 值插入的讨论. 1, PL/SQL 中可以执行插入''或者NULL 的操作, 前提是栏位允许为空. 2, 可以对NULL进行一系列数据库运算. 如:   ...

  7. ZOJ 1004 Anagrams by Stack(DFS+数据结构)

    Anagrams by Stack 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4 题目大意:输入两个字符串序列,判 ...

  8. 流形(Manifold)初步【转】

    转载自:http://blog.csdn.net/wangxiaojun911/article/details/17076465 欧几里得几何学(Euclidean Geometry) 两千三百年前, ...

  9. hdu_1003_Max Sum

    Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  10. Gtest打桩函数

    假设Client的定义如下 class Client { ...... public: virtual bool GetData(std::string& data); ...... }; 我 ...