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. 【jmeter】测试报告优化<一>

    具体问题如下: 1.Date report这里的时间没有正确显示出来 2.Summary里的字段Min Time和Max Time显示的是NaN,没有显示正确的时间. 本文主要解决上述两个问题,具体报 ...

  2. 【jmeter】JMeter函数学习

    JMeter函数是一些能够转化在测试树中取样器或者其他配置元件的域的特殊值.一个函数的调用就像这样:${_functionName(var1,var2,var3)},-functionName匹配函数 ...

  3. devstack安装openstack

    devstack是目前安装OpenStack最为方便的工具,一般用于开发和测试OpenStack.如果想在生产环境安装的话,需要对 devstack做很多定制,或者使用puppet/chef等更成熟的 ...

  4. 剑指offer系列21--二叉搜索树的后续遍历序列

    * 21[题目]输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果. * 如果是则输出Yes,否则输出No.假设输入的数组的任意两个数字都互不相同. * [注]二叉搜索树特点:左子树比根结 ...

  5. php Xdebug调试

    php开发环境里,安装了xdebug模块后,var_dump()输出的结果将比较易于查看,但默认情况下,var_dump() 输出的结果将有所变化:过多的数组元素不再显示,字符串变量将只显示前N个字符 ...

  6. 查看CentOS版本方法

    查看内核版本 这个命令适用于所有的linux,包括Redhat.SuSE.Debian.Centos等发行版. root@MyMail ~ # uname Linux root@MyMail ~ # ...

  7. 【MySQL】insert批量插入优化方案

    对于一些数据量较大的系统,数据库面临的问题除了查询效率低下,还有就是数据入库时间长.特别像报表系统,每天花费在数据导入上的时间可能会长达几个小时或十几个小时之久.因此,优化数据库插入性能是很有意义的. ...

  8. 【SQL Server】系统学习之三:逻辑查询处理阶段-六段式

    一.From阶段 针对连接说明: 1.笛卡尔积 2.on筛选器 插播:unknown=not unknuwn 缺失的值: 筛选器(on where having)把unknown当做FALSE处理,排 ...

  9. android 通知

    https://developer.android.com/design/patterns/notifications.html 通知系统可让用户随时了解应用中的相关和即时事件,例如来自好友的新聊天信 ...

  10. capture同focus

    SetCapture函数功能:该函数在属于当前线程的指定窗口里设置鼠标捕获.一旦窗口捕获了鼠标,所有鼠标输入都针对该窗口,无论光标是否在窗口的边界内.同一时刻只能有一个窗口捕获鼠标.如果鼠标光标在另一 ...