当前位置:网站首页>[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();
}
边栏推荐
猜你喜欢
Countermeasures for the failure of MMPV billing period caused by negative inventory of materials in SAP mm
Japan bet on national luck: Web3.0, anyway, is not the first time to fail!
I did it with two lines of code. As a result, my sister had a more ingenious way
Find love for speed in F1 delta time Grand Prix
不会看器件手册的工程师不是个好厨子
[true topic of the Blue Bridge Cup trials 43] scratch space flight children's programming explanation of the true topic of the Blue Bridge Cup trials
运维必备——ELK日志分析系统
Unity skframework framework (XII), score scoring module
de4000h存储安装配置
【OpenGL】笔记二十九、高级光照(镜面高光)
随机推荐
Sum of the first n terms of Fibonacci (fast power of matrix)
【youcans 的图像处理学习课】总目录
Engineers who can't read device manuals are not good cooks
[Unity]使用GB2312,打包后程序不正常解决方案
最近公共祖先LCA的三种求法
口袋奇兵点评
Download files and preview pictures
MAC (MacOS Monterey 12.2 M1) personal use PHP development
[cloud native database] what to do when encountering slow SQL (Part 1)?
解答:EasyDSS视频点播时音频是否可以设置为默认开启?
Can automatically update the universal weekly report template, you can use it with your hand!
Don't spend money, spend an hour to build your own blog website
你的 Sleep 服务会梦到服务网格外的 bookinfo 吗
OpenFOAM:lduMatrix&lduAddressing
Numpy array calculation
Student course selection information management system based on ssm+jsp framework [source code + database]
[unity] using GB2312, the solution to abnormal program after packaging
Let juicefs help you with "remote backup"
Redis数据库持久化
Memory management 01 - link script