当前位置:网站首页>[USACO05JAN]Watchcow S(欧拉回路)
[USACO05JAN]Watchcow S(欧拉回路)
2022-07-02 10:14:00 【Joanh_Lan】
[USACO05JAN]Watchcow S
题目描述
Farmer John 有 N N N 个农场( 2 ≤ N ≤ 1 0 4 2 \leq N \leq 10^4 2≤N≤104),这些农场由 M M M 条道路连接( 1 ≤ M ≤ 5 × 1 0 4 1 \leq M \leq 5 \times 10^4 1≤M≤5×104)。不保证没有重边。
Bassie 从 1 1 1 号农场开始巡逻,每条路必须从两个方向各走恰好一遍,最后回到 1 1 1 号农场。
请输出一条满足上述要求的路径。
保证这样的路径存在。如果有多条路径,任意输出一条即可。
输入格式
第一行两个整数 N , M N,M N,M。
接下来 M M M 行,每行两个整数 u , v u,v u,v,描述一条 u u u 到 v v v 的道路。
输出格式
输出经过的农场,一行一个。
样例 #1
样例输入 #1
4 5
1 2
1 4
2 3
2 4
3 4
样例输出 #1
1
2
3
4
2
1
4
3
2
4
1
思路:
无向图转有向图 --> 跑有向图的欧拉回路
AC代码如下:
#include <bits/stdc++.h>
#define buff \ ios::sync_with_stdio(false); \ cin.tie(0);
//#define int long long
using namespace std;
const int N = 1e4 + 9, M = 1e5 + 9;
int n, m;
int e[M], h[M], ne[M], idx;
int s[M], cnt;
bool st[M];****
void add(int a, int b)
{
e[idx] = b;
ne[idx] = h[a];
h[a] = idx++;
}
void dfs(int x)
{
for (int i = h[x]; ~i; i = ne[i])
{
if (!st[i])
{
st[i] = true;
int j = e[i];
dfs(j);
s[++cnt] = j;
}
}
}
void solve()
{
memset(h, -1, sizeof h);
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
int u, v;
cin >> u >> v;
add(u, v);
add(v, u);
}
dfs(1);
s[++cnt] = 1;
for (int i = cnt; i >= 1; i--)
cout << s[i] << '\n';
}
int main()
{
buff;
solve();
}
边栏推荐
- We sincerely invite young creators to share with investors and entrepreneurs how to make choices in life in the metauniverse
- Verification failed, please check your call back website. You can follow the instructions
- Unity SKFramework框架(十六)、Package Manager 開發工具包管理器
- Android kotlin material design technology points
- Crowncad (crown CAD), the first fully independent 3D CAD platform based on Cloud Architecture in China
- Unity SKFramework框架(二十)、VFX Lab 特效库
- Redis数据库持久化
- Principle analysis of security rememberme
- 【OpenGL】笔记二十九、高级光照(镜面高光)
- OpenAPI generator: simplify the restful API development process
猜你喜欢
Unity skframework Framework (XVI), package manager Development Kit Manager
De4000h storage installation configuration
TVOC, VOC, VOCs gas detection + Solution
Unity SKFramework框架(二十一)、Texture Filter 贴图资源筛选工具
2022 zero code / low code development white paper [produced by partner cloud] with download
Research shows that "congenial" is more likely to become friends
Performance optimization of memory function
Unity skframework framework (XIV), extension extension function
Unity skframework framework (XIX), POI points of interest / information points
Error function ERF
随机推荐
Crowncad (crown CAD), the first fully independent 3D CAD platform based on Cloud Architecture in China
OpenApi-Generator:简化RESTful API开发流程
操作教程:EasyDSS如何将MP4点播文件转化成RTSP视频流?
免费SSL证书知多少?免费SSL证书和收费SSL证书的区别
The second anniversary of the three winged bird: the wings are getting richer and the take-off is just around the corner
记忆函数的性能优化
为什么switch 的default后面要跟break?
【蓝桥杯选拔赛真题43】Scratch航天飞行 少儿编程scratch蓝桥杯选拔赛真题讲解
伙伴云表格强势升级!Pro版,更非凡!
[Unity]使用GB2312,打包后程序不正常解决方案
Drawing Nyquist diagram with MATLAB
[technology development-22]: rapid overview of the application and development of network and communication technology-2-communication Technology
Three talking about exception -- error handling
Nohup command
JS reverse row query data decryption
Unity small map production [2]
Unity skframework framework (XV), singleton singleton
Solution: Compression Technology (original version and sequel version)
[unity] using GB2312, the solution to abnormal program after packaging
Let juicefs help you with "remote backup"