• POJ


    https://vjudge.net/problem/POJ-2230

    求无向图从起点1开始从不同方向经过所有边的一条路径,输出任意一条。


    欧拉回路改了一点。

    就是反向边不同时标记

    #include<iostream> 
    #include<cstdio>
    
    #define ri register int
    #define u int
    
    namespace opt {
        
        inline u in() {
            u x(0),f(1);
            char s(getchar());
            while(s<'0'||s>'9') {
                if(s=='-') f=-1;
                s=getchar();
            }
            while(s>='0'&&s<='9') {
                x=(x<<1)+(x<<3)+s-'0';
                s=getchar();
            }
            return x*f;
        }
        
    }
    
    using opt::in;
    
    #define NN 10005
    #define MM 50005
    
    namespace mainstay {
        
        u h[NN],cnt(1);
        
        struct node{
            u to,next;
        }a[MM<<1];
        
        inline void add(const u &x,const u &y){
            a[++cnt].to=y,a[cnt].next=h[x],h[x]=cnt;
        }
        
        u vt[MM<<1];
        
        void dfs(const u &x){
            for(ri i(h[x]);i;i=a[i].next){
                u _y(a[i].to);
                if(!vt[i]){
                    vt[i]=1;
                    dfs(_y);
                    //ans[++ans[0]]=_y;
                }
            }
            printf("%d
    ",x);
        }
        
        inline void solve(){
            u N(in()),M(in());
            for(ri i(1);i<=M;++i){
                u _a(in()),_b(in());
                add(_a,_b),add(_b,_a);
            }
            dfs(1);
            //for(ri i(ans[0]);i>=1;--i) printf("%d
    ",ans[i]);
        }
        
    }
    
    int main() {
        
        //freopen("x.txt","r",stdin);
        std::ios::sync_with_stdio(false);
        mainstay::solve();
        
    }
  • 相关阅读:
    Jeronimo's List Gym
    Jeronimo's List Gym
    Text Editor Gym
    Text Editor Gym
    树上最长距离模板
    树上最长距离模板
    Purple Rain Gym
    数制转化2
    小括号匹配
    数制转化
  • 原文地址:https://www.cnblogs.com/ling-zhi/p/11771209.html
Copyright © 2020-2023  润新知