1. 程式人生 > >8.4--圖的割邊

8.4--圖的割邊

//8.4 圖的割邊

#include<cstdio>
int n,m,e[9][9],root;
int num[9],low[9],flag[9],index;
int min(int a,int b)
{
    return a<b?a:b;
}
void dfs(int cur,int father)
{
    int child=0,i,j;
    index++;
    num[cur]=index;
    low[cur]=index;
    for(i=1;i<=n;i++)
    {
        if(e[cur][i]==1
) { if(num[i]==0) { child++; dfs(i,cur); low[cur]=min(low[cur],low[i]); if(low[i]>num[cur]) printf("%d-%d\n",cur,i); } else if(i!=father) { low[cur]=min(low[cur],num[i]); } } } } int
main() { freopen("data.in","r",stdin); int i,j,x,y; scanf("%d%d",&n,&m); for(i=1;i<=n;i++) for(j=1;j<=n;j++) e[i][j]=0; for(i=1;i<=m;i++) { scanf("%d%d",&x,&y); e[x][y]=1; e[y][x]=1; } root=1; dfs(1
,root); return 0; }