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. Angular学习(8)- 路由

    示例: <!DOCTYPE html> <html ng-app="MyApp"> <head> <title>Study 12&l ...

  2. 【linux】chmod命令详细用法

    功能说明: 变更文件或目录的权限 u:User,即文件或目录的拥有者. g:Group,即文件或目录的所属群组. o:Other,除了文件或目录拥有者或所属群组之外,其他用户皆属于这个范围. a:Al ...

  3. Neutron GRE模式要注意的问题

    GRE模式下,如果MTU和Offloading配置不当,会严重降低网络性能(https://ask.openstack.org/en/question/6140/quantum-neutron-gre ...

  4. 【Spring-AOP-1】AOP相关概念

    Advice (好多中文书籍翻译为:增强处理,比如前向增强.后向增强等) 描述了Aspect类执行的具体动作.the job of an aspect. 定义了如下两个方面: what:即Aspect ...

  5. Spring实战6:利用Spring和JDBC访问数据库

    主要内容 定义Spring的数据访问支持 配置数据库资源 使用Spring提供的JDBC模板 写在前面:经过上一篇文章的学习,我们掌握了如何写web应用的控制器层,不过由于只定义了SpitterRep ...

  6. Hadoop:使用原生python编写MapReduce

    功能实现 功能:统计文本文件中所有单词出现的频率功能. 下面是要统计的文本文件 [/root/hadooptest/input.txt] foo foo quux labs foo bar quux ...

  7. Android SDK的docs访问速度很慢(新)

    #设置环境变量 名称:ANDROID_SDK_HOME 值:我的为-->E:\android\android-sdk #代码编译及运行 1.把下面的代码保存为:AndroidDocRepair. ...

  8. 黄聪:mysql下使用update set from select

    UPDATE friends INNER JOIN users ON friends.friendid=users.userid SET friends.friendname=users.userna ...

  9. 黄聪:wordpress如何使用get_avatar禁止调用gravatar头像,替换为自定义头像

    add_filter( 'get_avatar' , 'my_custom_avatar' , 1 , 5 ); function my_custom_avatar( $avatar, $id_or_ ...

  10. iphone dev 入门实例4:CoreData入门

    The iPhone Core Data Example Application The application developed in this chapter will take the for ...