Description

Suppose that G is an undirected graph, and the value of stab is defined as follows: Among the expression,G -i, -j is the remainder after removing node i, node j and all edges that are directly relevant to the previous two nodes. cntCompent is the number of connected components of X independently.  Thus, given a certain undirected graph G, you are supposed to calculating the value of stab.
 

Input

The input will contain the description of several graphs. For each graph, the description consist of an integer N for the number of nodes, an integer M for the number of edges, and M pairs of integers for edges (3<=N,M<=5000).  Please note that the endpoints of edge is marked in the range of [0,N-1], and input cases ends with EOF.
 

Output

For each graph in the input, you should output the value of stab.

题目大意:给一个n个点m条边的无向图,删掉任意两个点,求最大联通分量数。

思路:枚举要被删掉的第一个点,然后用tarjan求剩下的每一个点被删掉后能增加的联通分量数。根据dfs的性质,有多少个分支的lowu ≥ pre[u],删掉u后就有多少个联通分量,删掉第一个点的时候剩下的块数加上删掉第二个点的联通分量数,就是删掉第一个点可以获得的最大连通分量数。要注意的是,如果要删掉的点是一个孤立的点,那么它的连通分量数反而会减少。时间复杂度为O(nm),12S可以承受。

代码(5000MS):

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std; const int MAXN = ;
const int MAXE = MAXN * ; int head[MAXN];
int to[MAXE], next[MAXE];
int pre[MAXN], cut[MAXN];
int n, m, dfs_clock, ecnt, stab; void init() {
memset(head, , sizeof(head));
ecnt = ;
} void add_edge2(int u, int v) {
to[ecnt] = v; next[ecnt] = head[u]; head[u] = ecnt++;
to[ecnt] = u; next[ecnt] = head[v]; head[v] = ecnt++;
} int del; int dfs(int u, int fa) {
int lowu = pre[u] = ++dfs_clock;
for(int p = head[u]; p; p = next[p]) {
int &v = to[p];
if(v == del) continue;
if(!pre[v]) {
int lowv = dfs(v, u);
lowu = min(lowu, lowv);
if(lowv >= pre[u]) ++cut[u];
} else if(pre[v] < pre[u] && v != fa) {
lowu = min(lowu, pre[v]);
}
}
if(fa < ) --cut[u];
return lowu;
} int main() {
while(scanf("%d%d", &n, &m) != EOF) {
init();
while(m--) {
int a, b;
scanf("%d%d", &a, &b);
add_edge2(a, b);
}
stab = ;
for(int i = ; i < n; ++i) {
del = i;
int sum = ;
memset(pre, , sizeof(pre));
memset(cut, , sizeof(cut));
dfs_clock = ;
for(int u = ; u < n; ++u) {
if(u == i || pre[u]) continue;
++sum;
dfs(u, -);
}
int maxcut = -;
for(int u = ; u < n; ++u) if(u != i)
maxcut = max(maxcut, cut[u]);
stab = max(stab, sum + maxcut);
}
printf("%d\n", stab);
}
}

HDU 4587 TWO NODES(割点)(2013 ACM-ICPC南京赛区全国邀请赛)的更多相关文章

  1. HDU 4587 TWO NODES 割点

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

  2. 2013 ACM/ICPC南京邀请赛B题(求割点扩展)

    题目链接:http://icpc.njust.edu.cn/Contest/194/Problem/B B - TWO NODES 时间限制: 10000 MS 内存限制: 65535 KB 问题描述 ...

  3. HDU 4571 Travel in time ★(2013 ACM/ICPC长沙邀请赛)

    [题意]给定N个点,每个点有一个停留所需的时间Ci,和停留能够获得的满意度Si,有M条边,每条边代表着两个点走动所需的时间ti,现在问在规定的T时间内从指定的一点S到E能够获得的最大的满意度是多少?要 ...

  4. HDU 4758——Walk Through Squares——2013 ACM/ICPC Asia Regional Nanjing Online

    与其说这是一次重温AC自动机+dp,倒不如说这是个坑,而且把队友给深坑了. 这个题目都没A得出来,我只觉得我以前的AC自动机的题目都白刷了——深坑啊. 题目的意思是给你两个串,每个串只含有R或者D,要 ...

  5. hdu 4751 Divide Groups bfs (2013 ACM/ICPC Asia Regional Nanjing Online 1004)

    SDUST的训练赛 当时死磕这个水题3个小时,也无心去搞其他的 按照题意,转换成无向图,预处理去掉单向的边,然后判断剩下的图能否构成两个无向完全图(ps一个完全图也行或是一个完全图+一个孤点) 代码是 ...

  6. 2013 ACM/ICPC 南京网络赛F题

    题意:给出一个4×4的点阵,连接相邻点可以构成一个九宫格,每个小格边长为1.从没有边的点阵开始,两人轮流向点阵中加边,如果加入的边构成了新的边长为1的小正方形,则加边的人得分.构成几个得几分,最终完成 ...

  7. 2018 ACM ICPC 南京赛区 酱油记

    Day 1: 早上6点起床打车去车站,似乎好久没有这么早起床过了,困到不行,在火车上睡啊睡就睡到了南京.南航离南京南站很近,地铁一站就到了,在学校里看到了体验坐直升机的活动,感觉很强.报道完之后去吃了 ...

  8. HDU 4587 TWO NODES 枚举+割点

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

  9. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

随机推荐

  1. JVM由浅入深

    运行时数据区域 Java比起C++一个很大的进步就在于Java不用再手动控制指针的delete与free,统一交由JVM管理,但也正因为如此,一旦出现内存溢出异常,不了解JVM,那么排查问题将会变成一 ...

  2. BZOJ2754: [SCOI2012]喵星球上的点名(AC自动机)

    Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 2816  Solved: 1246[Submit][Status][Discuss] Descript ...

  3. poj_3256_Cow Picnic

    The cows are having a picnic! Each of Farmer John's K (1 ≤ K ≤ 100) cows is grazing in one of N (1 ≤ ...

  4. 安装mysqlclient报OSError: mysql_config not found

    输入命令: :~$ pip install mysqlclient 报错: Collecting mysqlclient Using cached https://files.pythonhosted ...

  5. oracle 11g grid软件安装[20180121]

      实验环境:     系统->Redhat 6.5     Oracle软件版本->oracle 11.2.0.4.0        系统初始化     设定hosts主机名和对应IP地 ...

  6. Java集合类——Set、List、Map、Queue接口

    目录 Java 集合类的基本概念 Java 集合类的层次关系 Java 集合类的应用场景 一. Java集合类的基本概念 在编程中,常需要集中存放多个数据,数组是一个很好的选择,但数组的长度需提前指定 ...

  7. bootstrap Table动态绑定数据并自定义字段显示值

    第一步:我们在官网下载了bootstrap 的文档,并在项目中引入bootstrap table相关js文件,当然,也要记得引入jquery文件 大概如图: 第二步:定义一个table控件 第三步:j ...

  8. 【tp5.1】微信公众号授权登录及获取信息录入数据库

    微信公众号开发文档链接:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1445241432 微信公众号授权登录分为两种: 1.以 ...

  9. Hadoop(4)--Hbase

    Hadoop 其它组成角色介绍--Hbase 在apache的官方网站上,对于Hbase的定义是他是Hadoop的第一个分布式.可扩展的大数据存储的数据库,他的目标是将非常大的表托管到一个集群中进行相 ...

  10. python三大神器之迭代器

    可迭代协议: 内部含有__iter__方法的值/变量都是可迭代的.可迭代类型和python语言之间的协议. 可迭代对象: iterable,内部包含__iter__()函数. 迭代器: iterato ...