TWO NODES
Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 547 Accepted Submission(s): 179
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
Source
2013 ACM-ICPC南京赛区全国邀请赛——题目重现
Recommend
Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 547 Accepted Submission(s): 179
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
Source
2013 ACM-ICPC南京赛区全国邀请赛——题目重现
Recommend
思路:枚举一个点,然后跑割点的连通块数。
#include<cstring>
#include<cstdio>
#include<iostream>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define clr(f,z) memset(f,z,sizeof f)
using namespace std;
const int mp=5009;
const int me=mp+mp;
class Edge
{
public:
int v,next;
};
class Graph_tree
{
public:
int head[mp],edge;
int block[mp],dfn[mp],dfs_clock;
bool mark[mp];
Edge e[me];
int n;
void clear()
{
clr(head,-1);edge=0;
}
void add(int u,int v)
{
e[edge].v=v;e[edge].next=head[u];head[u]=edge++;
}
int tarjan(int u,int rt)
{
int lowu,lowv,v;
lowu=dfn[u]=++dfs_clock;
mark[u]=1;
for(int i=head[u];~i;i=e[i].next)
{
v=e[i].v;
if(v==rt)continue;
if(!dfn[v])
{
lowv=tarjan(v,rt);
lowu=min(lowu,lowv);
if(lowv>=dfn[u])
++block[u];
}
else if(mark[v])
lowu=min(lowu,dfn[v]);
}
return lowu;
}
void getans()
{
int ans=0;
FOR(i,0,n-1)///the point erase
{
clr(dfn,0);clr(mark,0);//clr(block,0);
int num=0;dfs_clock=0;
FOR(j,0,n-1)
block[j]=1;///if no root block shuld add root
FOR(j,0,n-1)
if(i!=j&&!mark[j])
{
++num;
block[j]=0;
tarjan(j,i);
// cout<<num<<" "<<block[j]<<endl;
}
FOR(j,0,n-1)
if(i!=j)
ans=max(ans,num+block[j]-1);
}
printf("%d\n",ans);
}
}sp;
int main()
{
int n,m,a,b;
while(~scanf("%d%d",&n,&m))
{
sp.clear();
sp.n=n;
FOR(i,0,m-1)
{
scanf("%d%d",&a,&b);
sp.add(a,b);sp.add(b,a);
}
//puts("++");
sp.getans();
}
return 0;
}
本文介绍了一个图算法问题,通过枚举节点并使用Tarjan算法来计算稳定性值。具体地,对于给定的无向图,文章提供了计算所有节点对删除后的连通块数量的方法,旨在找出图中最稳定的节点组合。

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



