TWO NODES
Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 379 Accepted Submission(s): 142
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
Recommend
zhuyuanchen520
思路:枚举第一个点,然后用tarjan求出剩下图中联通最大的割点。然后让第一个去掉的点形成的块加上第二个割点所形成的联通分量就是第一个点所能形成的最佳的答案,然后枚举第一个点求出一个最大值就好了。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#define maxn 5500
using namespace std;
vector< int >G[maxn];
int ans,tot,dfs_clock,pre[maxn],low[maxn],iscut[maxn];
int dfs(int u,int f,int d){
int lowu=pre[u]=++dfs_clock;
for(int i=0;i<(int)G[u].size();i++){
int v=G[u][i];
if(v==d) continue;
if(!pre[v]){
int lowv=dfs(v,u,d);
lowu=min(lowu,lowv);
if(lowv>=pre[u]) iscut[u]++;
}else if(pre[v]<pre[u]&&v!=f){
lowu=min(lowu,pre[v]);
}
}
if(f<0) iscut[u]--;
low[u]=lowu;
return lowu;
}
void init(int n){
dfs_clock=tot=0;
memset(pre,0,sizeof(pre));
memset(iscut,0,sizeof(iscut));
}
int main(int argc,char **argv){
int n,m;
while(~scanf("%d%d",&n,&m)){
for(int i=0;i<n;i++)
G[i].clear();
for(int i=1;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
G[u].push_back(v);
G[v].push_back(u);
}
ans=0;
for(int i=0;i<n;i++){
init(n);
for(int u=0;u<n;u++){
if(u==i||pre[u])continue;
dfs(u,-1,i);tot++;
}
int maxx=-1;//这里坑啊!!!!
//cout<<i<<' '<<tot<<endl;
for(int u=0;u<n;u++){
//cout<<iscut[u]<<' ';
if(u==i) continue;
maxx=max(maxx,iscut[u]);
}
//cout<<endl;
ans=max(ans,maxx+tot);
//cout<<'#'<<ans<<endl;
}
printf("%d\n",ans);
}
}

此博客探讨了如何在一个无向图中去除任意两点后,计算剩余部分形成的最大独立集合数量。通过枚举和图论算法(如Tarjan算法),实现高效计算。案例分析和代码实现提供了具体解决方案。
2729

被折叠的 条评论
为什么被折叠?



