当前位置:网站首页>[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();
}
边栏推荐
- Uniapp develops wechat applet Tencent map function and generates sig signature of location cloud
- Which do you choose between Alibaba P7 with an annual salary of 900000 and deputy department level cadres?
- Partner cloud form strong upgrade! Pro version, more extraordinary!
- JS逆向之行行查data解密
- 能自动更新的万能周报模板,有手就会用!
- 屠榜多目标跟踪!BoT-SORT:稳健的关联多行人跟踪
- The 29 year old programmer in Shanghai was sentenced to 10 months for "deleting the database and running away" on the day of his resignation!
- Unity skframework framework (XVIII), roamcameracontroller roaming perspective camera control script
- Unity skframework framework (XIV), extension extension function
- Sum of the first n terms of Fibonacci (fast power of matrix)
猜你喜欢

题解《子数整数》、《欢乐地跳》、《开灯》

What are eNB, EPC and PGW?
![[Blue Bridge Cup] children's worship circle](/img/ad/5af4fe76ad5d1426bc460904d7f049.jpg)
[Blue Bridge Cup] children's worship circle

Three methods of finding LCA of the nearest common ancestor

代码实现MNLM

Unity skframework framework (XIV), extension extension function

Unity skframework framework (XIX), POI points of interest / information points

TVOC, VOC, VOCs gas detection + Solution

Gee learning notes 2

Research shows that "congenial" is more likely to become friends
随机推荐
TVOC, VOC, VOCs gas detection + Solution
互联网常见34个术语解释
Unity skframework framework (XIV), extension extension function
Nohup command
验证失败,请检查您的回电网址。您可以按照指导进行操作
Download files and preview pictures
Essential for operation and maintenance - Elk log analysis system
[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
2022 zero code / low code development white paper [produced by partner cloud] with download
JS逆向之巨量创意signature签名
Explanation: here is your UFO, Goldbach conjecture
Quantum three body problem: Landau fall
Astro learning notes
Engineers who can't read device manuals are not good cooks
Redis数据库持久化
Web基础
Pocket Raider comments
【云原生数据库】遇到慢SQL该怎么办(上)?
Why is the default of switch followed by break?
[technology development-22]: rapid overview of the application and development of network and communication technology-2-communication Technology