TWO NODES HDU - 4587

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

题目大意:从无向图中选取两个点删掉,问删掉后的图连通分量个数最多是多少

解题思路:枚举每一个要删掉的点,然后进行tarjan算法(dfs)查找删掉这个点后,最大的强连通分量,注意:删掉一个点后整个图就有可能不是联通图。

#include 
#include 
#define status string
using namespace std;
const int MAXN=5009;
const int MAXM=100019;
struct node
{
    int to,next;
} edge[MAXM];
int index,tot;
int low[MAXN],dfn[MAXN];
int add_block[MAXN];
int head[MAXN];
void addedge(int u,int v)
{
    edge[tot].to=v;
    edge[tot].next=head[u];
    head[u]=tot++;
}
void Tarjan(int u,int pre,int forbid)
{
    int v;
    low[u]=dfn[u]=++index;
    //cout<low[v])low[u]=low[v];
            if(u!=pre&&low[v]>=dfn[u])
                add_block[u]++;
        }
        else if(low[u]>dfn[v])
            low[u]=dfn[v];
    }
    if(u==pre)add_block[u]=son-1;
}
void init()
{
    memset(add_block,0,sizeof(add_block));
    memset(dfn,0,sizeof(dfn));
    index=0;
}

int main()
{
    int n,m,u,v;
    while(~scanf("%d %d",&n,&m))
    {
        tot=0;
        memset(head,-1,sizeof(head));
        for(int i=1; i<=m; i++)
        {
            scanf("%d %d",&u,&v);
            addedge(u,v);
            addedge(v,u);
        }
        int ans=0;
        for(int i=0;i

 

你可能感兴趣的:(割点)