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

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

Posted by wjjay003 at 2012-04-25 13:39:59 on Problem 2230
In Reply To:求这两个代码的区别!!!!!!!!! Posted by:wjjay003 at 2012-04-25 13:38:54
第一个AC第二个就是wa呀,难道他们不是一样的么?只是顺序换了一下而已
> #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