luogu P2731 骑马修栅栏 Riding the Fences

Posted jackpei

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

以上是关于luogu P2731 骑马修栅栏 Riding the Fences的主要内容,如果未能解决你的问题,请参考以下文章