TWO NODES
Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1452 Accepted Submission(s): 442
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.

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.
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
Source
题意
一张图,要求去掉两个点之后连通分量最多,求这个最大值。
题解
直接暴力枚举第一个去掉的点,在剩下的图上跑tarjan算法就好(代码比较丑。。内存突破天际。。时间突破天际。。我还是太弱了。。。)
代码
#include <cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int E[5005][5005];
int Enum[5005];
int dfn[5005];
int low[5005];
int son[5005];
int N,M;
int u,v;
int T;
int del;
int root;
void dfs(int x,int fa)
{
low[x]=dfn[x]=T++;
int cnt=0;
for(int i=0;i<Enum[x];i++)
{
if(E[x][i]==fa||E[x][i]==del)
continue;
else if(dfn[E[x][i]])
low[x]=min(low[x],dfn[E[x][i]]);
else if(!dfn[E[x][i]])
{
dfs(E[x][i],x);
cnt++;
if(x!=root&&low[E[x][i]]>=dfn[x])
son[x]++;
low[x]=min(low[x],low[E[x][i]]);
}
}
if(x==root)
son[x]=cnt-1;
}
int main()
{
while(scanf("%d%d",&N,&M)!=EOF)
{
int ans=0;
memset(Enum,0,sizeof Enum);
for(int i=0;i<M;i++)
{
scanf("%d%d",&u,&v);
E[u][Enum[u]++]=v;
E[v][Enum[v]++]=u;
}
for(del=0;del<N;del++)
{
T=1;
int temp=0;
memset(dfn,0,sizeof dfn);
memset(low,0,sizeof low);
memset(son,0,sizeof son);
for(int i=0;i<N;i++)
{
if(i!=del&&dfn[i]==0)
{
root=i;
dfs(i,-1);
temp++;
}
}
for(int i=0;i<N;i++)
{
if(i==del)
continue;
ans=max(ans,temp+son[i]);
}
}
printf("%d\n",ans);
}
return 0;
}