1738 - 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

来源

2013 ACM-ICPC China Nanjing Invitational Programming Contest
 
#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#pragma comment(linker, "/STACK:10240000000000,10240000000000")
using namespace std;
typedef long long LL ;
const int Max_N= ;
struct Edge{
int v ;
int next ;
};
Edge edge[Max_N*] ;
int id ,indx ;
int vec[Max_N] ,dfn[Max_N] ,low[Max_N] ;
bool visited[Max_N];
void add_edge(int u ,int v){
edge[id].v=v ;
edge[id].next=vec[u] ;
vec[u]=id++ ;
}
void init(){
id= ;
indx= ;
memset(vec,-,sizeof(vec)) ;
}
int ans ,root_son ;
int can_use[Max_N] ; void dfs(int u ,bool is_root){
dfn[u]=low[u]=++indx ;
visited[u]= ;
int child = ;
for(int e=vec[u];e!=-;e=edge[e].next){
int v=edge[e].v ;
if(can_use[v]==)
continue ;
if(!dfn[v]){
dfs(v,) ;
if(is_root)
root_son++ ;
else{
low[u]=Min(low[u],low[v]) ;
if(low[v]>=dfn[u])
child++ ;
}
}
else
low[u]=Min(low[u],dfn[v]) ;
}
ans=Max(ans ,child+) ; //注意+1
} int tarjan(int root){
if(vec[root]==-) //块内就一个点的情况
return ;
memset(dfn,,sizeof(dfn)) ;
ans= ; //删除当前块里面的某点产生的分量数
root_son= ;
dfs(root,) ;
ans=Max(ans,root_son) ;
return ans ;
} int main(){
int N ,M ,u ,v ,ans ,child ,sum;
while(scanf("%d%d",&N,&M)!=EOF){
init() ;
sum= ;
while(M--){
scanf("%d%d",&u,&v) ;
add_edge(u,v) ;
add_edge(v,u) ;
}
memset(can_use,,sizeof(can_use)) ;
for(int k=;k<N;k++){
can_use[k]= ;
child= ;
ans= ;
memset(visited,,sizeof(visited)) ;
for(int i=;i<N;i++){
if(can_use[i]==)
continue ;
if(!visited[i]){
child++ ;
ans=Max(ans,tarjan(i)) ;
}
}
//cout<<child+ans-1<<endl ; //原来就有1块
int now=child+ans- ;
sum=Max(sum,now) ;
can_use[k]= ;
}
cout<<sum<<endl ;
}
return ;
}

1738 - TWO NODES的更多相关文章

  1. [LeetCode] Count Complete Tree Nodes 求完全二叉树的节点个数

    Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...

  2. [LeetCode] Reverse Nodes in k-Group 每k个一组翻转链表

    Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If ...

  3. [LeetCode] Swap Nodes in Pairs 成对交换节点

    Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...

  4. Swap Nodes in Pairs

    Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...

  5. Leetcode-24 Swap Nodes in Pairs

    #24. Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For ...

  6. No.025:Reverse Nodes in k-Group

    问题: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list ...

  7. No.024:Swap Nodes in Pairs

    问题: Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1-> ...

  8. Reverse Nodes in k-Group

    Reverse Nodes in k-Group Given a linked list, reverse the nodes of a linked list k at a time and ret ...

  9. Count Complete Tree Nodes

    Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...

随机推荐

  1. jQuery validate在没有校验通过的情况下拒绝提交

    下面通过一个简单的例子说明,这个问题,可能是很多人遇到的,验证不通过的时候,依然提交了表单. HTML <form class="survey" id="surve ...

  2. 关于JAVA中事件分发和监听机制实现的代码实例-绝对原创实用

    http://blog.csdn.net/5iasp/article/details/37054171 文章标题:关于JAVA中事件分发和监听机制实现的代码实例 文章地址: http://blog.c ...

  3. NotifyIcon用法

    -------------------控件NotifyIcon-----------//客户端调用 private void btnShowError_Click(object sender, Eve ...

  4. android关于AndroidManifest.xml详细分析

    http://my.eoe.cn/1087692/archive/5927.html 一.关于AndroidManifest.xmlAndroidManifest.xml 是每个android程序中必 ...

  5. [系统集成] CI持续集成项目简介

    一.问题的产生 公司的多个部门围绕着产品开发.测试.发布.维护,设置有不同的岗位和系统,这些岗位和系统缺少有效的整合,没有实现自动化,效率不是很高,因此就有了CI(持续集成)的项目需求. 二.解决方案 ...

  6. Python处理Excel文档(xlrd, xlwt, xlutils)

    简介 xlrd,xlwt和xlutils是用Python处理Excel文档(*.xls)的高效率工具.其中,xlrd只能读取xls,xlwt只能新建xls(不可以修改),xlutils能将xlrd.B ...

  7. 【转】SVN服务器客户端以及环境的搭建和使用

    vss,cvs,svn三者都是版本控制工具 vss是锁定-编辑-解锁模式,svn虽然也支持锁定,但默认是修改-冲突-合并模式 vss的版本号对应的是单个文件,svn的版本号对应的是整个版本库 vss是 ...

  8. TMS320C54x系列DSP的CPU与外设——第8章 流水线

    第8章 流水线 本章描述了TMS320C54x DSP流水线的操作,列出了对不同寄存器操作时的流水线延迟周期.(对应英语原文第7章) 8.1 流水线操作 TMS320C54x DSP有一个6段的指令流 ...

  9. C#中abstract和virtual区别

    在C#的学习中,容易混淆virtual方法和abstract方法的使用,现在来讨论一下二者的区别.二者都牵涉到在派生类中与override的配合使用. 一.Virtual方法(虚方法) virtual ...

  10. Navicat(连接)-1

    连接 要在 Navicat 开始使用你的服务器,你要首先用连接窗口创建一个或多个连接.如果你是一个服务器新手和不肯定如何工作,你可能想看看: MySQL 用户手册 Oracle 数据库文件 Postg ...