| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
求这两个代码的区别!!!!!!!!!#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator