当前位置:网站首页>[usaco05jan]watchcow s (Euler loop)
[usaco05jan]watchcow s (Euler loop)
2022-07-02 13:45:00 【Joanh_ Lan】
[USACO05JAN]Watchcow S
Title Description
Farmer John Yes N N N A farm ( 2 ≤ N ≤ 1 0 4 2 \leq N \leq 10^4 2≤N≤104), These farms are owned by M M M Two roads connect ( 1 ≤ M ≤ 5 × 1 0 4 1 \leq M \leq 5 \times 10^4 1≤M≤5×104). There is no guarantee that there is no heavy edge .
Bassie from 1 1 1 Farm No. 1 starts patrolling , Each road must go in two directions Just once , Finally back to 1 1 1 Farm No .
Please output a path that meets the above requirements .
Ensure that such a path exists . If there are multiple paths , Just output any one .
Input format
The first line has two integers N , M N,M N,M.
Next M M M That's ok , Two integers per line u , v u,v u,v, Describe a u u u To v v v The path of .
Output format
Output through the farm , A line of one .
Examples #1
The sample input #1
4 5
1 2
1 4
2 3
2 4
3 4
Sample output #1
1
2
3
4
2
1
4
3
2
4
1
Ideas :
Undirected graph to directed graph --> Euler loop of running digraph
AC The code is as follows :
#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();
}
边栏推荐
- 口袋奇兵点评
- Why can't d link DLL
- Three methods of finding LCA of the nearest common ancestor
- [youcans' image processing learning course] general contents
- Explanation of 34 common terms on the Internet
- Node.js通过ODBC访问PostgreSQL数据库
- Web基础
- 693. 行程排序(map + 拓扑)
- Essential for operation and maintenance - Elk log analysis system
- [OpenGL] notes 29. Advanced lighting (specular highlights)
猜你喜欢
De4000h storage installation configuration
Web Foundation
[indomitable medal activity] life goes on and writing goes on
Qt-制作一个简单的计算器-实现四则运算-将结果以对话框的形式弹出来
TVOC, VOC, VOCs gas detection + Solution
leetcode621. 任务调度器
Integral link, inertia link and proportion link in Simulink
Node.js通过ODBC访问PostgreSQL数据库
EasyDSS点播服务分享时间出错如何修改?
为什么switch 的default后面要跟break?
随机推荐
Skillfully use SSH to get through the Internet restrictions
What are eNB, EPC and PGW?
D language, possible 'string plug-ins'
Node.js通过ODBC访问PostgreSQL数据库
uniapp小程序 subPackages分包配置
Drawing Nyquist diagram with MATLAB
Pocket Raider comments
2、 Frame mode MPLS operation
Daily practice of C language --- monkeys divide peaches
OpenApi-Generator:简化RESTful API开发流程
【youcans 的图像处理学习课】总目录
错误:EACCES:权限被拒绝,访问“/usr/lib/node_modules”
【文档树、设置】字体变小
2022零代码/低代码开发白皮书【伙伴云出品】附下载
Sum of the first n terms of Fibonacci (fast power of matrix)
验证失败,请检查您的回电网址。您可以按照指导进行操作
Android kotlin fragment technology point
机器学习基础(二)——训练集和测试集的划分
伙伴云表格强势升级!Pro版,更非凡!
Qt-制作一个简单的计算器-实现四则运算-将结果以对话框的形式弹出来