原题链接

类欧拉回路,要求每条边被正反各经过一次,且从\(1\)出发并回到\(1\)。

只需每次搜索该点的边时,将该点的边对应的邻接表头及时修改为下一条即可,因为邻接表恰好储存了正反方向的边,所以及时更新表头就能保证每条边被正反各经过一次。

#include<cstdio>
using namespace std;
const int N = 1e4 + 10;
const int M = 5e4 + 10;
int fi[N], di[M << 1], ne[M << 1], an[M << 1], l, k;
inline int re()
{
int x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return p ? -x : x;
}
inline void add(int x, int y)
{
di[++l] = y;
ne[l] = fi[x];
fi[x] = l;
}
void dfs(int x)
{
int i;
for (i = fi[x]; i; i = fi[x])
{
fi[x] = ne[i];
dfs(di[i]);
}
an[++k] = x;
}
int main()
{
int i, n, m, x, y;
n = re();
m = re();
for (i = 1; i <= m; i++)
{
x = re();
y = re();
add(x, y);
add(y, x);
}
dfs(1);
for (i = k; i; i--)
printf("%d\n", an[i]);
return 0;
}

POJ2230 Watchcow的更多相关文章

  1. POJ2230 Watchcow【欧拉回路】

    Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6172Accepted: 2663 Special Judge ...

  2. poj2230 Watchcow【欧拉回路】【输出路径】(遍历所有边的两个方向)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4392 题目大意: 一个图,要将每条边恰好遍历两遍,而且要以不同的方向,还要回到原点. dfs解法    ...

  3. 【POJ2230】Watchcow

    题目大意:给定一个 N 个点,M 条边的无向图,要求不重复地经过每条边两次,并且从 1 号节点出发最后回到 1 号节点,求一条路径. 题解:不重复地经过两次这个操作很容易地通过无向图的建边方式来实现, ...

  4. Watchcow(POJ2230+双向欧拉回路+打印路径)

    题目链接:http://poj.org/problem?id=2230 题目: 题意:给你m条路径,求一条路径使得从1出发最后回到1,并满足每条路径都恰好被沿着正反两个方向经过一次. 思路:由于可以回 ...

  5. poj2230 欧拉回路

    http://poj.org/problem?id=2230 Description Bessie's been appointed the new watch-cow for the farm. E ...

  6. [欧拉] poj 2230 Watchcow

    主题链接: http://poj.org/problem? id=2230 Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submi ...

  7. POJ22230 Watchcow (欧拉回路)

    Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6477   Accepted: 2823   Specia ...

  8. POJ 2230 Watchcow(有向图欧拉回路)

    Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the ...

  9. POJ 2230 Watchcow (欧拉回路)

    Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5258   Accepted: 2206   Specia ...

随机推荐

  1. NYOJ44-子串和-(dp||思维)

    题目描述: 给定一整型数列{a1,a2...,an},找出连续非空子串{ax,ax+1,...,ay},使得该子序列的和最大,其中,1<=x<=y<=n. 输入描述: 第一行是一个整 ...

  2. Linux 安装nginx 及配置

    安装openssl库   # yum install -y openssl openssl-devel 安装gcc     # yum install gcc-c++ 安装 PCRE    # yum ...

  3. git gitlab 使用 提交代码解决冲突

    1.更改完代码后,git push 发生错误 注: 此时,使用 git pull: 更新代码,git 会自动merge不同的更新, a.  如果git 自动merge成功,再进行 git push操作 ...

  4. 自己电脑能ping别人的,但别人电脑去不能跟我们的电脑通信

    记住一点:多半时防火墙出了问题. 打开“控制面板”——点击“系统和安全”——“Windows防火墙”——点击“打开或关闭”Windows防火墙--点击家庭组网络或者工作组网络——关闭家庭组和工作组的防 ...

  5. IE 兼容background-size

    1:修改src *background-size: cover;//兼容ie的background-size filter: progid:DXImageTransform.Microsoft.Alp ...

  6. flume 实际的使用

    1.No configuration found for this host:seqGenSrc bin/flume-ng agent --conf conf --conf-file conf/flu ...

  7. xlwt使用

    xlwt引入xlwt,import xlwt 新建工作簿,xlsx = xlwt.Workbook( encoding="utf-8" ),参数:设置编码为utf-8 添加工作表, ...

  8. 媒体类型 & 媒体查询

    [媒体类型 & 媒体查询] @media 规则允许在相同样式表为不同媒体设置不同的样式. 在下面的例子告诉我们浏览器屏幕上显示一个14像素的Verdana字体样式.但是如果页面打印,将是10个 ...

  9. .Net下几种ORM框架的对比

    1.Entity Framework(重量级)2.NHibernate(重量级)3.Dapper(轻量级)4.PetaPoco(轻量级)5.MyBatis.Net (介于EF和Dapper之间) 对比 ...

  10. Hibernate框架学习笔记

      Hibernate 是一个 JDO( Java Data Objects)工具.它的工作原理是通过文件把值对象(Java对象)和 数据库表之间建立起一个映射关系,还提供数据查询和获取数据的方法. ...