hdu4587TWO NODES【割点】

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
题意:已知无向图选两个点点从原图中删掉,剩下的最大连通分量个数?

做法:很容易想到应该从个点入手,然而就算枚举割点,要怎么算呢?(下午试试这种枚举所有割点的方法)

本题的解法是第一个点枚举所有点,第二个点由dfs求出最大值。具体来说就是iscut原来表示是否是割点,现在让他作为“遍历时成为割点的次数”即为子树的个数。

那么对于非根节点,删去后剩余个数为iscut[i] + 1(子树个数加上父节点),根节点为iscut[i] (没有父节点)

那么全题答案便是 max(iscut[i] + 1) + left - 1

#pragma comment(linker, "/STACK:102400000000,102400000000")
#include 
#include
#include
#include
#include
using namespace std;
#define maxn 5009
vectorG[maxn];
int pre[maxn],dfs_cnt,iscut[maxn];
int n,m,none;
void init()
{
    for(int i=0;i=pre[u])
                iscut[u]++;
        }
        else if(pre[v]


你可能感兴趣的:(—图论,———连通性,2-SAT)