Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

OLE????....不就是求桥吗????

Posted by c4pt0r at 2008-09-10 14:47:15 on Problem 1515
#include <iostream>
#define MAXN 1010
using namespace std;
int deg[MAXN];
int s[MAXN];
int low[MAXN];
int g[MAXN][MAXN];
int v_stack[MAXN],w_stack[MAXN];
int dfn;
int n_stack;
int dfs(int v,int pre)
{
    int i,w;
    int cnt;
    
    dfn++;
    low[v]=s[v]=dfn;
    for(i=1;i<=deg[v];i++)
    {
       w=g[v][i];
       if(s[w]<s[v] && w!=pre) //反向边 
       {
          v_stack[n_stack]=v;
          w_stack[n_stack]=w; 
          n_stack++;
       }
       if(s[w]==0)//前向边 
       {
          dfs(w,v);
          if(low[w]>=s[v])
          {
             //找到新的连通分支
             cnt=0;
             while(v_stack[n_stack-1]!=v || w_stack[n_stack-1]!=w)
             {
                 cout<<v_stack[n_stack-1]<<" "<<w_stack[n_stack-1]<<endl;
                 n_stack--;
                 cnt++;
             } 
             cout<<v_stack[n_stack-1]<<" "<<w_stack[n_stack-1]<<endl;
             if(cnt==0)
             {
                   cout<<w_stack[n_stack-1]<<" "<<v_stack[n_stack-1]<<endl;  
             }
             n_stack--;  
          }
          else{
             low[v]=low[v]<low[w]?low[v]:low[w];
          }
       }
       else{
           low[v]=low[v]<s[w]?low[v]:s[w]; 
       }
    }
}

int main()
{
    int i,j,m,n,cases=1;
    while(cin>>n>>m)
    {
       if(m==n && n==0) break;
       memset(deg,0,sizeof(deg));
       memset(low,0,sizeof(low));
       memset(s,0,sizeof(s));
       memset(v_stack,0,sizeof(v_stack));
       memset(w_stack,0,sizeof(w_stack));
       memset(g,0,sizeof(g));
       for(int a=0;a<m;a++)
       {
          cin>>i>>j;
          deg[i]++;deg[j]++;
          g[i][deg[i]]=j;
          g[j][deg[j]]=i;
       } 
       n_stack=1;
       dfn=0;
       cout<<cases++<<endl<<endl;
       dfs(1,-1);
       cout<<"#"<<endl;
    }
    
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator