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

求这两个代码的区别!!!!!!!!!

Posted by wjjay003 at 2012-04-25 13:38:54 on Problem 2230
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std  ;

const int maxn = 10000+10 ;
const int maxe = 50000*2+10 ;

int to[maxe] , nxt[maxe] ;
int head[maxn] , vis[maxe] ;
int n , m , cnt ;

void addedge( int u , int v )
{
    to[cnt] = v ;
    nxt[cnt] = head[u] ;
    head[u] = cnt++ ;
}

void dfs( int u )
{
    for( int e = head[u] ; e!=-1 ; e=nxt[e] )
    {
        int v = to[e] ;
        if( !vis[e] )
        {
            vis[e] = 1 ;
            dfs( v );
        }
    }
    cout << u << endl ;
}

int main()
{
    int u , v ;
    while(scanf("%d%d",&n,&m)!=EOF )
    {
        memset(head,-1,sizeof(head));
        memset(vis,0,sizeof(vis));
        cnt = 0 ;
        for( int i = 0 ; i < m ; ++i )
        {
            scanf("%d%d",&u,&v);
            addedge(u,v);
            addedge(v,u);
        }
        dfs(1);
    }
    return 0 ;
}
------------------------------------------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std  ;

const int maxn = 10000+10 ;
const int maxe = 50000*2+10 ;

int to[maxe] , nxt[maxe] ;
int head[maxn] , vis[maxe] ;
int n , m , cnt ;

void addedge( int u , int v )
{
    to[cnt] = v ;
    nxt[cnt] = head[u] ;
    head[u] = cnt++ ;
}

void dfs( int u )
{
    cout << u << endl ;
    for( int e = head[u] ; e!=-1 ; e=nxt[e] )
    {
        int v = to[e] ;
        if( !vis[e] )
        {
            vis[e] = 1 ;
            dfs( v );
        }
    }
}

int main()
{
    int u , v ;
    while(scanf("%d%d",&n,&m)!=EOF )
    {
        memset(head,-1,sizeof(head));
        memset(vis,0,sizeof(vis));
        cnt = 0 ;
        for( int i = 0 ; i < m ; ++i )
        {
            scanf("%d%d",&u,&v);
            addedge(u,v);
            addedge(v,u);
        }
        dfs(1);
    }
    return 0 ;
}

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