首页 > 其他 > 详细

luogu P2731 骑马修栅栏 Riding the Fences

时间:2019-04-11 19:21:42      阅读:152      评论:0      收藏:0      [点我收藏+]

入度为奇数的点,搜他。

最好邻接矩阵。。。

#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\n",stk[top]);
}

2019.04.11

luogu P2731 骑马修栅栏 Riding the Fences

原文:https://www.cnblogs.com/Jackpei/p/10691627.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!