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 ...
随机推荐
- Android 实现布局动态加载
Android 动态加载布局 通过使用LayoutInflater 每次点击按钮时候去读取布局文件,然后找到布局文件里面的各个VIEW 操作完VIEW 后加载进我们setContentView 方面里 ...
- 解决eclipse-helios中Errors running builder JavaScript Validator的问题
原文:http://blog.ywxyn.com/index.php/archives/713 解决eclipse-helios中Errors running builder JavaScript V ...
- MVC 简单发送邮件示例
没啥好说的 直接上代码 @{ try { WebMail.SmtpServer = "smtp.qq.com";//SMTP邮件服务器 WebMail.SmtpPort = ;// ...
- CodeForces Round #297 Div.2 E (中途相遇法)
当时打比赛的时候卡在D题了,没有看E.现在看来E还是不难的. 将n个数排序后,其实不排序也是可以的,只是排序能快一半的时间. 枚举前一半能得到多少种和,放到map里面: 然后在后一半数中枚举,然后在m ...
- 【第八篇】mvc razor视图配置404 500页面
记住是最外层的这个Web.config 在 <system.web> </system.web>节点里面配置 <customErrors defaultRedirect ...
- Android custom View AirConditionerView hacking
package com.example.arc.view; import android.content.Context; import android.graphics.Canvas; import ...
- cURL: PHP并发处理方式
function classic_curl($urls, $delay) { $queue = curl_multi_init(); $map = array(); foreach ($urls as ...
- wxWidgets简单的多线程
#include <wx/wx.h> #include <wx/thread.h> #include <wx/event.h> #include <wx/pr ...
- strust2 配置chainAction结果类型的配置
<result name="chainAction" type="chain"> <param name="actionName&q ...
- webservices上传文件
客户端: ob_clean(); ob_start(); readfile("D:/44.jpg"); $logo = ob_get_clean(); $pararmArr = a ...