#include <bits/stdc++.h>
using namespace std; const int N = ;
const int M = ; struct Edge {
int to, next;
} edge[M];
int head[N];
int cntE;
void addedge(int u, int v) {
edge[cntE].to = v; edge[cntE].next = head[u]; head[u] = cntE++;
edge[cntE].to = u; edge[cntE].next = head[v]; head[v] = cntE++;
} int dfn[N], low[N], idx;
int stk[N], top;
bool cut[N];
int block[N];
// 一个割点可能在很多个连通分量
// 如果一个双连通分量内的某些顶点在一个奇圈中(即双连通分量含有奇圈
// 那么这个双连通分量的其他顶点也在某个奇圈中
// 如果一个双连通分量含有奇圈,则他必定不是一个二分图。反过来也成立,这是一个充要条件。
int no;
// block[i] 是去掉i这个节点能够多几个联通块
void tarjan(int u, int fa) {
dfn[u] = low[u] = ++idx;
stk[top++] = u;
block[u] = ;
int son = ;
for (int i = head[u]; ~i; i = edge[i].next) {
int v = edge[i].to;
if (v == fa || v == no) continue;
if (!dfn[v]) {
son++;
tarjan(v, u);
low[u] = min(low[u], low[v]);
if (u != fa && low[v] >= dfn[u]) {
cut[u] = true;
block[u]++;
}
/* 求每一个连通分量
if (low[v] >= dfn[u]) { int x;
do {
x = stk[--top];
push(x);
} while (x != v);
push(u);
}
*/
} else {
low[u] = min(low[u], dfn[v]);
}
}
if (u == fa) {
if (son > ) cut[u] = ;
block[u] = son-;
}
} void init() {
memset(dfn, , sizeof dfn);
top = idx = cntE = ;
} int main()
{
int n, m;
while (~scanf("%d%d", &n, &m)) {
int u, v;
memset(head, -, sizeof head);
for (int i = ; i < m; ++i) {
scanf("%d%d", &u, &v);
addedge(u, v);
}
int ans = ;
for (u = ; u < n; ++u) {
init(); int cnt = ; no = u;
for (v = ; v < n; ++v) {
if (v != u && !dfn[v]) {
tarjan(v, v);
cnt++;
}
}
for (v = ; v < n; ++v) {
if (v != u) ans = max(ans, cnt + block[v]);
}
}
printf("%d\n", ans);
}
return ;
}

hdu4587-TWO NODES(割点)的更多相关文章

  1. HDU 4587 TWO NODES 割点

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4587 题意: 删除两个点,使连通块的数目最大化 题解: 枚举删除第一个点,然后对删除了第一个点的图跑 ...

  2. hdu4587 TWO NODES

    问一个无向图中去掉任意两点后剩下的连通分量的个数最大值 枚举第一个删去的点,在剩下的子图中求割点 注意,剩下的子图可能不连通,那么就要对每个连通块求割点 计算删去一个点后剩余连通分量个数 left 的 ...

  3. hdu4587 Two Nodes 求图中删除两个结点剩余的连通分量的数量

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 题目给了12000ms,对于tarjan这种O(|V|+|E|)复杂度的算法来说,暴力是能狗住的 ...

  4. 备战noip week8

    POJ1144 网络 description: 给出一张\(N\)个点的无向图,求其中割点的个数 data range: \(N\le 100\) solution: 一道模板题(但是读入实在是把我恶 ...

  5. HDU 4587 TWO NODES 枚举+割点

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 TWO NODES Time Limit: 24000/12000 MS (Java/Other ...

  6. HDU4587--TWO NODES(无向图割点,暴力出奇迹)这是我见过的时间最长的题。。。

    TWO NODES Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total ...

  7. HDU - 4587 TWO NODES (图的割点)

    Suppose that G is an undirected graph, and the value of stab is defined as follows: Among the expres ...

  8. HDU 4587 TWO NODES(割点)(2013 ACM-ICPC南京赛区全国邀请赛)

    Description Suppose that G is an undirected graph, and the value of stab is defined as follows: Amon ...

  9. POJ1523 SPF[无向图割点]

    SPF Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8139   Accepted: 3723 Description C ...

随机推荐

  1. 探讨read的返回值的三种情况

    http://blog.chinaunix.net/uid-23629988-id-3035613.html 今天探讨一个很看似简单的API “read”的返回值问题.read的返回值有哪几个值?每个 ...

  2. 镜面电火花EDM加工技术资料,模具行业的人应该好好看看!

    目前镜面电火花加工技术在精密型腔模具制造中逐步得以推广.本文就企业中镜面电火花加工应用的关键环节,结合实践分析了影响镜面加工性能的因素.通过控制各个工艺环节,可有效实现高质量.高效率的镜面电火花加工. ...

  3. POJ1416——Shredding Company(DFS)

    Shredding Company DescriptionYou have just been put in charge of developing a new shredder for the S ...

  4. 算法总结之欧拉函数&中国剩余定理

    算法总结之欧拉函数&中国剩余定理 1.欧拉函数 概念:在数论,对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目. 通式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)( ...

  5. C++中的namespace用法

    关键字namespace定义了一个名字空间,里面的变量和函数,声明在此名字空间外使用须在前面加名字空间名称.例如: #include<iostream.h>namespace my{ in ...

  6. 【剑指offer】数字在排序数组中出现的次数

    2013-09-02 16:28:35 找出数字在排序数组中出现的次数. 注意几点: 一开始试图用size_t类型表示数组的下标begin.end,到那时这样做在end = 0时,end - 1是si ...

  7. js标点符号全局匹配

    var modelCode = node.modelCode.replace(/\./g, '\_'); 注意后面的  "\" <script language=" ...

  8. ajax withCredentials在firefox下问题的解释

    1,起因: 跨域的问题一般有两种解决方式比较常用,一是使用jsonp,二是服务端配置cors策略.至于jsonp这里不再赘述,本文主要解释一下cors解决跨域产生的问题 2,cors跨域产生的问题 j ...

  9. Java 简单登录MVC

    构建一个简单的基于MVC模式的JavaWeb 零晨三点半了,刚刚几个兄弟一起出去吼歌,才回来,这应该是我大学第二次去K歌,第一次是大一吧,之后每次兄弟喊我,我都不想去,因为我还是很害怕去KTV,或许是 ...

  10. s​e​t​ ​x​a​c​t​_​a​b​o​r​t ​用​法

    默认行为 默认为SET XACT_ABORT OFF,没有事务行为. SET XACT_ABORT ON SET XACT_ABORT ON分为两种: 1.总体作为一个事务,整体提交或整体回滚,格式为 ...