ArcTan

dfs
随笔 - 16, 文章 - 117, 评论 - 6, 引用 - 0
数据加载中……

连通图--顶点连通度的求解 POJ 1966

有向图G中求顶点连通度:
      1、独立轨P(A,B)
      2、Menger定理:无向图G的顶点连通度
               k(G)=V|G|-1 G是完全图,min <A,B>! in E(P(A,B))else
      3、用最大流法求P(A,B)。
      4、建图:e=(u,v)分成e'=(u'',v')和e''=(u',v'');e'=e''=inf。
     

得好好研究研究这些图论的原理,搞明白。《图论》这本书,讲得不行啊!!!!还是得好好学习《算法导论》

最大流,好要好好学!
10485949wangsouc1966Accepted248K16MSC++1967B2012-07-19 17:00:20
#include<stdio.h>
#include
<string.h>
#include
<math.h>
#include
<algorithm>
#define maxn 105
#define inf 105
#define min(x,y) (x<y?x:y)
#define max(x,y) (x>y?x:y)
using namespace std;
int map[maxn][maxn];
int N,M;
int max_flow(int num,int map[][maxn],int source,int sink)
{
    
int que[maxn],head,tail;
    
int pre[maxn],min_flow[maxn];

    
int flow[maxn][maxn];
    
int ans=0;
    memset(flow,
0,sizeof(flow));
    
while (1)
    {
        head
=0;tail=1;
        que[
1]=source;
        memset(pre,
-1,sizeof(pre));
        min_flow[source]
=inf;
        pre[source]
=-2;
        
while (head<tail)
        {
            
int temp=que[++head];
            
for (int i=0;i<num;i++)
            {
                
if (pre[i]==-1 && flow[temp][i]<map[temp][i])
                {
                    que[
++tail]=i;
                    pre[i]
=temp;
                    min_flow[i]
=min(min_flow[temp],(map[temp][i]-flow[temp][i]));
                }
            }
            
if (pre[sink]!=-1)
            {
                
int k=sink;
                
while (pre[k]>=0)
                {
                    flow[pre[k]][k]
+=min_flow[sink];
                    flow[k][pre[k]]
=-flow[pre[k]][k];
                    k
=pre[k];
                }
                
break;
            }
        }
        
if (pre[sink]==-1)
            
return ans;
        
else
            ans
+=min_flow[sink];
    }
}
int main()
{
    
while (scanf("%d%d",&N,&M)==2)
    {
        
int u,v,ans;
        
int i;
        memset(map,
0,sizeof(map));
        
for (i=0;i<N;i++)
            map[i][i
+N]=1;
        
for (i=0;i<M;i++)
        {
            scanf(
" (%d,%d)",&u,&v);
            map[u
+N][v]=map[v+N][u]=inf;
        }
        ans
=inf;
        
for (i=1;i<N;i++)
        {
            ans
=min(ans,max_flow(N*2,map,0+N,i));   //这里没有搞明白怎么是<N , i>呢???
        }
        
if (ans==inf)
            ans
=N;
        printf(
"%d\n",ans);
    }
    
return 0;
}

图论。



posted on 2012-07-19 17:09 wangs 阅读(468) 评论(0)  编辑 收藏 引用 所属分类: ACM-图论


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理