2013 ACM/ICPC南京邀请赛B题(求割点扩展)
题目链接:http://icpc.njust.edu.cn/Contest/194/Problem/B
B - TWO NODES
时间限制: | 10000 MS |
内存限制: | 65535 KB |
问题描述
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(X) 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 consists of multiple cases.
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.
输出说明
For each graph in the input, you should output the value of stab.
输入样例
4 5
0 1
1 2
2 3
3 0
0 2
输出样例
2
南京邀请赛的B题。。。。
一道饮恨的题目,那个时候太弱了,n=5000,复杂度为O(n^2)的算法不敢去搞了,时限竟然有10s
那个时候对求割点不熟悉。
最近搞了下连通图,弄了下割点和桥的求法。
然后写了下这题,写完1A了。
这题就是去掉两个点,问可以最多留下多少个连通分支。(现场比赛有提问说了,去掉的是两个不同的点)
枚举第一个去掉的点。然后就是普通的求割点的过程来实现去掉一个点可以增加多少个连通块。
然后就搞出来了
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
using namespace std;
const int MAXN = ;
const int MAXM = ; struct Edge
{
int to,next;
}edge[MAXM];
int head[MAXN],tot;
int Low[MAXN],DFN[MAXN],Stack[MAXN];
int Index,top;
bool Instack[MAXN];
bool cut[MAXN];
int add_block[MAXN]; void addedge(int u,int v)
{
edge[tot].to = v;edge[tot].next = head[u];head[u] = tot++;
} int subindex; void Tarjan(int u,int pre)
{
int v;
DFN[u] = Low[u] = ++Index;
Stack[top++] = u;
Instack[u] = true;
int son = ;
for(int i = head[u];i != -;i = edge[i].next)
{
v = edge[i].to;
if(v == pre)continue;
if(v == subindex)continue;
if(!DFN[v])
{
son++;
Tarjan(v,u);
if(Low[u] > Low[v])Low[u] = Low[v];
if(u != pre && Low[v] >= DFN[u])
{
cut[u] = true;
add_block[u]++;
}
}
else if(Instack[v] && Low[u] > DFN[v])
Low[u] = DFN[v];
}
if(u == pre && son > )cut[u] = true;
if(u == pre )add_block[u] = son - ;
Instack[u] = false;
top--;
}
int solve(int N)
{
memset(DFN,,sizeof(DFN));
memset(Instack,false,sizeof(Instack));
memset(add_block,,sizeof(add_block));
memset(cut,false,sizeof(cut));
Index = top = ;
int cnt = ;
int ans = ;
for(int i = ;i < N;i++)
if(i != subindex &&!DFN[i])
{
Tarjan(i,i);
cnt++;
}
for(int i = ;i < N;i++)
if(i != subindex)
ans = max(ans,cnt + add_block[i]);
return ans; }
void init()
{
tot = ;
memset(head,-,sizeof(head));
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)==)
{
init();
int u,v;
while(m--)
{
scanf("%d%d",&u,&v);
addedge(u,v);
addedge(v,u);
}
int ans = ;
for(int i = ;i < n;i++)
{
subindex = i;
ans = max(ans,solve(n));
}
printf("%d\n",ans);
}
return ;
}
2013 ACM/ICPC南京邀请赛B题(求割点扩展)的更多相关文章
- hdu 4587 2013南京邀请赛B题/ / 求割点后连通分量数变形。
题意:求一个无向图的,去掉两个不同的点后最多有几个连通分量. 思路:枚举每个点,假设去掉该点,然后对图求割点后连通分量数,更新最大的即可.算法相对简单,但是注意几个细节: 1:原图可能不连通. 2:有 ...
- 2013 ACM/ICPC 南京网络赛F题
题意:给出一个4×4的点阵,连接相邻点可以构成一个九宫格,每个小格边长为1.从没有边的点阵开始,两人轮流向点阵中加边,如果加入的边构成了新的边长为1的小正方形,则加边的人得分.构成几个得几分,最终完成 ...
- HDU 4571 Travel in time ★(2013 ACM/ICPC长沙邀请赛)
[题意]给定N个点,每个点有一个停留所需的时间Ci,和停留能够获得的满意度Si,有M条边,每条边代表着两个点走动所需的时间ti,现在问在规定的T时间内从指定的一点S到E能够获得的最大的满意度是多少?要 ...
- hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
- hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...
- hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...
- hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup
hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...
- 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 ...
- hduoj 4707 Pet 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4707 Pet Time Limit: 4000/2000 MS (Java/Others) Memory ...
随机推荐
- HDU 1506 Largest Rectangle in a Histogram
这个问题姑且也叫做最大子矩阵吧 给一个树状图,求一个最大面积的子矩阵 思路是这样的,对于每个单位矩阵,求出左边连续不比它低的矩阵的下标,放在l数组里 同样,再求出右边连续的不比它低的矩阵的下标 这样, ...
- [转]使用 jQuery Mobile 与 HTML5 开发 Web App —— jQuery Mobile 事件详解
在前文<使用 jQuery Mobile 与 HTML5 开发 Web App —— jQuery Mobile 默认配置与事件基础>中,Kayo 对 jQuery Mobile 事件的基 ...
- Linux kernel scriptes bin2c "\x"
/**************************************************************************** * Linux kernel scripte ...
- Windows Server 2003 激活码及激活方法
Windows Server 2003 简体中文企业版,真正免激活. CD-KEY:JB88F-WT2Q3-DPXTT-Y8GHG-7YYQY 安装序列号:JCGMJ-TC669-KCBG7-HB8X ...
- ArcEngine 通过IRelationalOperator.Relation判断几何体相交
IRelationalOperator 接口: 1. Provides access to members that determine if a certain spatial relationsh ...
- memcache保存php的session 解决多服务器的session问题
PECL :: Package :: memcache 2.1.1 版本的 Changelog 中有一条: - Added experimental session storage support. ...
- Javascript的匿名函数
一.什么是匿名函数?在Javascript定义一个函数一般有如下三种方式:函数关键字(function)语句:function fnMethodName(x){alert(x);}函数字面量(Func ...
- hdu 3572 Task Schedule(最大流)2010 ACM-ICPC Multi-University Training Contest(13)——Host by UESTC
题意: 告诉我们有m个任务和k个机器.第i个任务需要ci天完成,最早从第ai天开始,最晚在第bi天结束.每台机器每天可以执行一个任务.问,是否可以将所有的任务都按时完成? 输入: 首行输入一个整数t, ...
- 利用ArcGIS Engine、VS .NET和Windows控件开发GIS应用
Dixon 原文 用ArcGIS Engine.VS .NET和Windows控件开发GIS应用 此过程说明适合那些使用.NET建立和部署应用的开发者,它描述了使用ArcGIS控件建立和部署 ...
- Textbox像百度一下实现下拉显示 z
List<string> Data = new List<string>(); string Randomstr = "功夫撒黑胡椒hcbvf蜂窝qwertyuiop ...