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 ...
随机推荐
- pandas 常用清洗数据(一)
数据源获取: https://www.kaggle.com/datasets 1. Look at the some basic stats for the ‘imdb_score’ column: ...
- JMeter学习(二十九)自动化badboy脚本开发技术(转载)
转载自 http://www.cnblogs.com/yangxia-test 一般人用badboy都是使用它的录制功能,其它badboy还是一款自动化的工具,它可以实现检查点.参数化.迭代.并发.报 ...
- java面试题:网络通信
网络分层 Q:OSI网络七层模型. Http Q:http协议的状态码有哪些?含义是什么? 200,服务器已成功处理了请求. 302,重定向. 400,错误请求. 401,未授权,请求要求身份验证. ...
- 高德地图开发者平台获取sHA1值
一般在 Application 中进行初始化 /** * 获取高德SHA1值 * */ public static String sHA1(Context context) { try { Pack ...
- RxJS之工具操作符 ( Angular环境 )
一 delay操作符 源Observable延迟指定时间,再开始发射值. import { Component, OnInit } from '@angular/core'; import { of ...
- @RequestMapping使用须知
----------------------siwuxie095 @RequestMapping 使用须知 使用 @RequestMapping 注解映射请求路径 即 你可以使用 @RequestMa ...
- f5 SNMP配置
1.选择监控终端 2.配置团体名称:
- IntelliJ IDEA 运行 Maven 项目
1.官方文档说IntelliJ IDEA已经自身集成了maven,则不用劳心去下载maven 2.导入一个程序,看是否是maven程序的关键在于工程之中有没有pom.xml这个文件,比如这里 3. ...
- 32位Server2008添加IIS
- [leetcode]252. Meeting Rooms会议室有冲突吗
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...