当前位置:网站首页>[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();
}
边栏推荐
- rxjs Observable 自定义 Operator 的开发技巧
- 2022 zero code / low code development white paper [produced by partner cloud] with download
- MAC (MacOS Monterey 12.2 M1) personal use PHP development
- 操作教程:EasyDSS如何将MP4点播文件转化成RTSP视频流?
- 【笔耕不辍勋章活动】生命不止,写作不息
- 为什么switch 的default后面要跟break?
- 文件的下载与图片的预览
- 代码实现MNLM
- 互联网常见34个术语解释
- Bridge of undirected graph
猜你喜欢

Japan bet on national luck: Web3.0, anyway, is not the first time to fail!

解答:EasyDSS视频点播时音频是否可以设置为默认开启?

Explanation: here is your UFO, Goldbach conjecture

Answer: can the audio be set to on by default during easydss video on demand?

mac(macos Monterey12.2 m1) 个人使用php开发

Pointer from entry to advanced (1)

Professor of Shanghai Jiaotong University: he Yuanjun - bounding box (containment / bounding box)

Node. JS accessing PostgreSQL database through ODBC

无向图的桥

Countermeasures for the failure of MMPV billing period caused by negative inventory of materials in SAP mm
随机推荐
Runhe hi3516 development board openharmony small system and standard system burning
Why can't d link DLL
OpenFOAM:lduMatrix&lduAddressing
你的 Sleep 服务会梦到服务网格外的 bookinfo 吗
BeanUtils--浅拷贝--实例/原理
Qt-制作一个简单的计算器-实现四则运算
uniapp小程序 subPackages分包配置
What are eNB, EPC and PGW?
伙伴云表格强势升级!Pro版,更非凡!
Pocket Raider comments
Let juicefs help you with "remote backup"
解答:EasyDSS视频点播时音频是否可以设置为默认开启?
We sincerely invite young creators to share with investors and entrepreneurs how to make choices in life in the metauniverse
Principle analysis of security rememberme
Engineers who can't read device manuals are not good cooks
Answer: can the audio be set to on by default during easydss video on demand?
[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
石子合并板子【区间DP】(普通石子合并 & 环形石子合并)
Common options of tcpdump command: Three
de4000h存储安装配置