TWO NODES

Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 2354    Accepted Submission(s): 780

Problem 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.
Sample Input
4 5
0 1
1 2
2 3
3 0
0 2
Sample Output
2
Source
 题意:在一个无向图中,删除两个点,使的连通分量最大 输出最大的联通分量
枚举一个点 然后在剩下的n个点中选取一个点做顶点 然后利用割顶的性质判断这n-1个点的可以拆成多少个联通分量
其实就是在判断割顶的地方iscut[u]++;
但我们需要注意的是当选取的点是根节点时:incut[u]=0,因为他是没有父亲的,意思就是上面没有联通分量了
所以不是根节点的初始值就是iscut[u]=1,因为他的父亲那块是一个联通分量
由于删点会导致这个图不联通,所以需要DFS,看有几个联通块sum
最后的答案就是 max(sum+iscut[i]-1)
这个减1是因为将一个联通块拆成iscut[i]个 那么本身的联通块就没有了
 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string.h>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const double PI=acos(-1.0);
const double eps=0.0000000001;
const int INF=1e9;
const int N=+;
int head[N];
int t,tot;
struct node{
int to,next;
}edge[N<<];
int low[N];
int dfn[N];
int iscut[N];
void init(){
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
t=;
}
void add(int u,int v){
edge[tot].to=v;
edge[tot].next=head[u];
head[u]=tot++;
}
int DFS(int u,int fa,int flag){
low[u]=dfn[u]=++t;
int child=;
for(int i=head[u];i!=-;i=edge[i].next){
int v=edge[i].to;
if(v==flag)continue;
if(dfn[v]==){
child++;
int lowv=DFS(v,u,flag);
low[u]=min(low[u],lowv);
if(lowv>=dfn[u]){
iscut[u]++;
}
}
else if(dfn[v]<dfn[u]&&v!=fa){
low[u]=min(low[u],dfn[v]);
}
}
if(fa<&&child==)low[u]=;
return low[u];
}
int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
memset(head,-,sizeof(head));
tot=;
for(int i=;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
add(u,v);
add(v,u);
}
int ans=;
for(int i=;i<n;i++){
int sum=;
init();
for(int j=;j<n;j++){
iscut[j]=;
}
iscut[i]=;
for(int j=;j<n;j++){
if(i==j)continue;
if(dfn[j])continue;
iscut[j]=;
sum++;
DFS(j,-,i); }
for(int j=;j<n;j++){
ans=max(ans,iscut[j]+sum-);
}
}
cout<<ans<<endl;
}
}

hdu 4587(枚举+割顶)的更多相关文章

  1. P3388 【模板】割点(割顶) 题解 (Tarjan)

    题目链接 P3388 [模板]割点(割顶) 解题思路 最近学的东西太杂了,多写点博客免得自己糊里糊涂的过去了. 这个题求割点,感觉这篇文章写得挺好. 割点是啥?如果去掉这个点之后连通图变成多个不连通图 ...

  2. poj 1144 Network 图的割顶判断模板

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8797   Accepted: 4116 Descripti ...

  3. POJ1144 Network 无向图的割顶

    现在打算重新学习图论的一些基础算法,包括像桥,割顶,双连通分量,强连通分量这些基础算法我都打算重敲一次,因为这些量都是可以用tarjan的算法求得的,这次的割顶算是对tarjan的那一类算法的理解的再 ...

  4. 图论(无向图的割顶):POJ 1144 Network

    Network   Description A Telephone Line Company (TLC) is establishing a new telephone cable network. ...

  5. uoj#67. 新年的毒瘤(割顶)

    #67. 新年的毒瘤 辞旧迎新之际,喜羊羊正在打理羊村的绿化带,然后他发现了一棵长着毒瘤的树. 这个长着毒瘤的树可以用n个结点m 条无向边的无向图表示.这个图中有一些结点被称作是毒瘤结点,即删掉这个结 ...

  6. 图论算法-Tarjan模板 【缩点;割顶;双连通分量】

    图论算法-Tarjan模板 [缩点:割顶:双连通分量] 为小伙伴们总结的Tarjan三大算法 Tarjan缩点(求强连通分量) int n; int low[100010],dfn[100010]; ...

  7. Tarjan求割点(割顶) 割边(桥)

    割点的定义: 感性理解,所谓割点就是在无向连通图中去掉这个点和所有和这个点有关的边之后,原先连通的块就会相互分离变成至少两个分离的连通块的点. 举个例子: 图中的4号点就是割点,因为去掉4号点和有关边 ...

  8. Tarjan求割点 || Luogu P3388 【模板】割点(割顶)

    题面:P3388 [模板]割点(割顶) 题解:无 代码: #include<cstdio> #include<iostream> #include<cstring> ...

  9. Doves and bombs UVA - 10765(统计割顶所连接的连通块的数量)

    题意:给定一个n个点的连通的无向图,一个点的“鸽子值”定义为将它从图中删去后连通块的个数. 求对应的点 和 每个点的“鸽子值” 用一个数组在判断割顶的那个地方 累加标记一下所连接的连通块的数量即可 初 ...

随机推荐

  1. CMU-准备

    TOEFL成绩90分以上,GPA大于3.0,GRE1250分以上(不做明确要求) 申请条件:GRE成绩,建议有专科成绩;托福250,雅思7.0;简历;3封推荐信 TOEFL(The Test of E ...

  2. 这段代码很Pythonic | 相见恨晚的 itertools 库

    前言 最近事情不是很多,想写一些技术文章分享给大家,同时也对自己一段时间来碎片化接受的知识进行一下梳理,所谓写清楚才能说清楚,说清楚才能想清楚,就是这个道理了. 很多人都致力于把Python代码写得更 ...

  3. DH密钥交换算法

    DH密钥交换算法:DH的全称为Diffie-Hellman ,该算法可以在需要安全传输的前提下,确定双方的对称密钥,该算法的核心在于双方的私钥没有进入网络传输流程,根据对方的公钥和己方的私钥,可以计算 ...

  4. Nginx+Tomcat简单负载均衡

    Nginx,Apache安装完成 复制Tomcat:    tomcat-8080    tomcat-8081 启动Tomcat8080: cd /usr/local/tomcat-8080/bin ...

  5. Python学习笔记之生成器、迭代器和装饰器

    这篇文章主要介绍 Python 中几个常用的高级特性,用好这几个特性可以让自己的代码更加 Pythonnic 哦 1.生成器 什么是生成器呢?简单来说,在 Python 中一边循环一边计算的机制称为 ...

  6. python3.x Day1 用户登录程序练习

    训练1: 模拟登陆: 1. 用户输入帐号密码进行登陆 2. 用户信息保存在文件内 3. 用户密码输入错误三次后锁定用户 login2.py: #!/usr/bin/env python # -*- c ...

  7. SocketServer 网络服务框架

    SocketServer简化了网络服务器的编写.它有4个类:TCPServer,UDPServer,UnixStreamServer,UnixDatagramServer.这4个类是同步进行处理的,另 ...

  8. gnuplot examples

    xy plot #set terminal jpeg #set output 'alfa.jpg' set terminal postscript eps font 24 set out 'U_vs_ ...

  9. springcloud(十三):Ribbon客户端负载均衡实例

    一.采用默认的负载均衡策略:RoundRobinRule 轮询策略 1.修改提供者原的控制类 在之前的eureka-client-provider项目的CenterController.java中加入 ...

  10. nyoj 93 汉诺塔(三)(stack)

    汉诺塔(三) 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 在印度,有这么一个古老的传说:在世界中心贝拿勒斯(在印度北部)的圣庙里,一块黄铜板上插着三根宝石针.印度 ...