HDU 4587 TWO NODES 割点
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4587
题意:
删除两个点,使连通块的数目最大化
题解:
枚举删除第一个点,然后对删除了第一个点的图跑割点更新答案。
代码:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std; const int maxn = ;
vector<int> G[maxn]; int n,m; int pre[maxn], low[maxn], iscut[maxn], dfs_clock;
int dfs(int u, int fa,int tag) {
int lowu = pre[u] = ++dfs_clock;
int child = ;
for (int i = ; i < G[u].size(); i++) {
int v = G[u][i];
if (v == tag||v==fa) continue;
if (!pre[v]) {
child++;
int lowv = dfs(v, u, tag);
lowu = min(lowu, lowv);
if (lowv >= pre[u]) {
iscut[u]++;
}
}
else if (pre[v] < pre[u] && v != fa) {
lowu = min(lowu, pre[v]);
}
}
if (fa < && child == ) iscut[u]--;
else if (fa < ) iscut[u]--;
low[u] = lowu;
return lowu;
} void init() {
for (int i = ; i < n; i++) G[i].clear();
} int main() {
while (scanf("%d%d", &n, &m) == && n) {
init();
for (int i = ; i < m; i++) {
int u, v;
scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
int ans = -;
for (int i = ; i < n; i++) {
memset(pre, , sizeof(pre));
memset(iscut, , sizeof(iscut));
dfs_clock = ;
int cnt = ;
for (int j = ; j<n; j++) {
if (j == i) continue;
if (!pre[j]) {
cnt++;
dfs(j, -, i);
}
}
for (int j = ; j < n; j++) {
if (j == i) continue;
ans = max(ans, iscut[j] + cnt);
}
}
printf("%d\n", ans);
}
return ;
}
HDU 4587 TWO NODES 割点的更多相关文章
- HDU 4587 TWO NODES 枚举+割点
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 TWO NODES Time Limit: 24000/12000 MS (Java/Other ...
- HDU - 4587 TWO NODES (图的割点)
Suppose that G is an undirected graph, and the value of stab is defined as follows: Among the expres ...
- 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 ...
- HDU 4587 TWO NODES(割两个点的最大连通分支数)
http://acm.hdu.edu.cn/showproblem.php?pid=4587 题意: 给一图,求割去两个点后所能形成的最大连通分支数. 思路: 对于这种情况,第一个只能枚举,然后在删除 ...
- hdu 4587(割点的应用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 思路:题目的意思很简单,就是删除任意2个节点以及关联的边,求图的最大连通分量数.我们知道删除割点 ...
- hdu 4587 推断孤立点+割点+ 删除点之后,剩下多少连通分量
做了非常久...... 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4587 先枚举删除的第一个点,第二个点就是找割点.没有割点当然也有答案 学到 ...
- HDU 4587 B - TWO NODES tarjan
B - TWO NODESTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。
题意:求一个无向图的,去掉两个不同的点后最多有几个连通分量. 思路:枚举每个点,假设去掉该点,然后对图求割点后连通分量数,更新最大的即可.算法相对简单,但是注意几个细节: 1:原图可能不连通. 2:有 ...
- 【HDOJ】4587 TWO NODES
Tarjan解无向图的割点和桥,参考白书. /* 4587 */ #include <iostream> #include <vector> #include <algo ...
随机推荐
- cocos2dx-lua 批量打包及修改
coco2dx目前大部分开发者肯定是用lua解决问题,问题来了,每次改一下lua配置可能你每次都得运行 cocos luacompile -p android 针对不同的平台,可能会有某些配置会略有不 ...
- IE6中position:fixed无效问题解决
在做页面右下脚对话框时,直接使用position:fixed;大部分浏览器很容易就能做到,但是在IE6中却发现不行,原来是IE6不支持position:fixed;这个属性. 虽然用JS肯定能解决这个 ...
- redistribute and Suboptimal routing
重分发和次优路由 基础环境 拓扑: 分别配置好基本的环境,包含ip地址,路由协议的启用,得到他们的路由表分别为 R1: R2: R3: R4: 1. 在R1上将eigrp和OSPF进行双向重 ...
- UI1_UIView层操作
// // ViewController.m // UI1_UIView层操作 // // Created by zhangxueming on 15/7/1. // Copyright (c) 20 ...
- 标识域 Identify Field
在对象中保存DB的ID字段,以维持内存对象和DB数据Row之间的identify. 关系DB使用key来区分数据行. 而内存对象不需要这样的键.因为对象系统能够保证身份确认. 读取时没有问题,但是为了 ...
- Ueditor 1.4.3 单独调用上传图片,或文件功能
第一步, 引入文件 <script src="ueditor/ueditor.config.js" type="text/javascript" char ...
- 让apache与mysql随着系统自动启动
让apache与mysql随着系统自动启动 在Linux中有一个文件/etc/rc.d/rc.local文件,其系统在启动时会自动加载该文件,我们可以把要启动的服务放入这个文件中即可. 添加以下代码:
- 纪念一下自己的第一篇cnblog
2016-08-1016:33:22 // Netease.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iost ...
- 3月3日(5) Roman to Integer
原题 Roman to Integer 题意很简单,把Roman字母翻译成int. 实现方式也不难,针对每个字符转成int,从右往左,依次判断,如果当前值比上一个值大则相加,小则相减. 什么,你问我怎 ...
- MySQL用命令行导出数据库
MySQL命令行导出数据库:首先进入cmd然后:1. cd C:\Program Files (x86)\MySQL\MySQL Server 5.1\bin2. mysqldump -uroot - ...