POJ2230 Watchcow
原题链接
类欧拉回路,要求每条边被正反各经过一次,且从\(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的更多相关文章
- POJ2230 Watchcow【欧拉回路】
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6172Accepted: 2663 Special Judge ...
- poj2230 Watchcow【欧拉回路】【输出路径】(遍历所有边的两个方向)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4392 题目大意: 一个图,要将每条边恰好遍历两遍,而且要以不同的方向,还要回到原点. dfs解法 ...
- 【POJ2230】Watchcow
题目大意:给定一个 N 个点,M 条边的无向图,要求不重复地经过每条边两次,并且从 1 号节点出发最后回到 1 号节点,求一条路径. 题解:不重复地经过两次这个操作很容易地通过无向图的建边方式来实现, ...
- Watchcow(POJ2230+双向欧拉回路+打印路径)
题目链接:http://poj.org/problem?id=2230 题目: 题意:给你m条路径,求一条路径使得从1出发最后回到1,并满足每条路径都恰好被沿着正反两个方向经过一次. 思路:由于可以回 ...
- poj2230 欧拉回路
http://poj.org/problem?id=2230 Description Bessie's been appointed the new watch-cow for the farm. E ...
- [欧拉] poj 2230 Watchcow
主题链接: http://poj.org/problem? id=2230 Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submi ...
- POJ22230 Watchcow (欧拉回路)
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6477 Accepted: 2823 Specia ...
- POJ 2230 Watchcow(有向图欧拉回路)
Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the ...
- POJ 2230 Watchcow (欧拉回路)
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5258 Accepted: 2206 Specia ...
随机推荐
- 手机端head部分
<!doctype html> <html lang="zh"> <head> <meta charset="utf-8&quo ...
- 静态html返回
在这篇文章中我们介绍后台路由的概念,后台的路由根据路径返回相应的内容, 首先我们建立一个服务器 let port = 3000 //监听端口let fs = require ('fs')//用来生成可 ...
- el-js中循环遍历el的集合
遇到问题的代码: var score=0; for(var i=0;i<${fn:length(tMovie.tComments) };i++){ score=${tMovie.tComment ...
- 关于log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).的问题
解决办法(非长久之计,折中) 将该方法插入到main函数中,可以自行打印日志信息了 BasicConfigurator.configure(); //自动快速地使用缺省Log4j环境.原文链接:htt ...
- 如何使用eclipse创建JAVA项目并写一个简单的HelloWorld
输入项目名称 点击完成(Finish) 原文地址:https://blog.csdn.net/qq_36798713/article/details/79530056
- SQL%ROWCOUNT作用
SQL%ROWCOUNT是一个游标属性,而SQL中的DML操作实际上是一种隐式的游标操作,在做insert,update,delete,merge以及select into操作时,Oracle会打开一 ...
- Django常用的模板标签
django 目前了解的各个文件的作用: manage.py: 运行服务 urls: 路由 views: 处理数据 传递给 html模板 html文件: 通过 {{变量名}}接收变量 通过 模板标 ...
- 简单的jQ代码
简单的jQ代码 /* * Lazy Load - jQuery plugin for lazy loading images * * Copyright (c) 2007-2012 Mika Tuup ...
- 模拟银行业务的JS实现
/*开户.存款.挂失.补卡.取款.转账.余额查询.密码修改.交易查询.锁定账号.解锁账号等*//*C#第7天 请参考by-Qy*/ using System;using System.Collecti ...
- 点击空白隐藏div
window.onload = function(){ $(document).click(function(e){ $("#loginWrap").css('display',' ...