TWO NODES(HDU-4587)

Problem 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

题意:给出一个 n 个点 m 条边的无向图,求从这个无向图中删除任意两点后,所能得到的独立连通分量的最大值

思路:容易想到从割点入手,因此第一个点先枚举所有点,第二个点通过 Tarjan 求割点的同时求出最大值,即原来用 iscut 表示是否为割点,现在用其来作为遍历时成为割点的次数,那么对于非根节点,删去后剩余个数为子树个数加父节点个数,即:iscut[i]+1,对于根节点,由于没有父节点,剩余个数为子节点个数,即:iscut[i]

最后通过 max(iscut[i]+sum) 即可得出最优解

Source Program

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define N 20001
#define MOD 16007
#define E 1e-6
#define LL long long
using namespace std;
int n,m;
vector G[N];
int dfn[N],low[N];
int iscut[N];
int block_cnt;
int Tarjan(int x,int father,int forbid){//forbid为禁止访问的点
    int lowx=dfn[x]=++block_cnt;
    int child=0;

    for(int i=0;i=dfn[x])
                iscut[x]++;
        }
        else
            lowx=min(lowx,dfn[y]);
    }

    if(father<0)
        iscut[x]--;

    return low[x]=lowx;
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF&&(n+m)){
        for(int i=0;i

 

你可能感兴趣的:(#,HDU,#,图论——图的连通性)