zoukankan      html  css  js  c++  java
  • luogu P2731 骑马修栅栏 Riding the Fences

    欧拉回路。

    入度为奇数的点,搜他。

    最好邻接矩阵。。。                                                                                                                                                                                                                                                                                                                                                 

    #include<cstdio>
    #include<iostream>
    #define R register int
    using namespace std;
    inline int g() {
        R ret=0,fix=1; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-1:fix;
        do ret=ret*10+(ch^48); while(isdigit(ch=getchar())); return ret*fix;
    }
    int m,top,mn,mx,st=1;
    int e[501][501],stk[1025],r[501];
    void dfs(int u) {
        for(R v=mn;v<=mx;++v) if(e[u][v])
            --e[u][v],--e[v][u],dfs(v);
        stk[++top]=u;
    }
    signed main() {
        m=g();
        for(R i=1,u,v;i<=m;++i) u=g(),v=g(),
            ++e[u][v],++e[v][u],++r[u],++r[v],
            mn=min(min(u,v),mn),mx=max(max(u,v),mx);
        for(R i=mn;i<=mx;++i) if(r[i]&1) {st=i; break;}
        dfs(st); for(;top>0;--top) printf("%d
    ",stk[top]);
    }

    2019.04.11

  • 相关阅读:
    1635:【例 5】Strange Way to Express Integers
    1633:【例 3】Sumdiv
    1632:【 例 2】[NOIP2012]同余方程
    1631:【例 1】青蛙的约会
    1629:聪明的燕姿
    1628:X-factor Chain
    1627:【例 3】最大公约数
    1626:【例 2】Hankson 的趣味题
    file_put_contens小trick
    billu b0x2靶机渗透
  • 原文地址:https://www.cnblogs.com/Jackpei/p/10691627.html
Copyright © 2011-2022 走看看