当前位置:网站首页>AcWing 1184. Euler circuit problem solving (Euler circuit)
AcWing 1184. Euler circuit problem solving (Euler circuit)
2022-07-22 11:17:00 【QingQingDE23】
AcWing 1184. Euler circuit
In this problem, you can directly use penetration 、 The method of judging whether it is Eulerian or not should be remembered , Also remember how to search the path and save the output
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, M = 4e5 + 10;
int h[N], e[M], ne[M], idx;
int ans[M]; // Save answer path
int din[N], dout[N]; // Store the penetration of each point 、 The degree of
int n, m;
int type; // Type of recording diagram
int used[M];
int cnt; // Record how many sides there are
void add(int a, int b){
e[idx] = b;
ne[idx] = h[a];
h[a] = idx ++ ;
}
void dfs(int u){
// Traverse from point
for(int &i = h[u]; ~i;){
//i Here is still the number of points , Add one & It can avoid repeatedly applying for space , Save time
if(used[i]){
i = ne[i];
continue;
}
// Marking this edge has been used
used[i] = true;
if(type == 1) used[i ^ 1] = true;
int t;
// Point to edge
if(type == 1){
// If it's an undirected graph
t = i / 2 + 1;
if(i & 1) t = -t; // If he comes from the end, it's the opposite side
}
else t = i + 1; // If it's a digraph , The number of edges is the number of points +1
int j = e[i];
i = ne[i];
dfs(j); // Go all the way Press the end into the stack first Then go back and add the middle and starting point to the stack Final output ans[cnt] As a starting point
ans[ ++ cnt] = t;
}
}
int main()
{
scanf("%d", &type);
scanf("%d%d", &n, &m);
memset(h, -1, sizeof h);
for(int i = 0; i < m; i ++ ){
int a, b;
scanf("%d%d", &a, &b);
add(a, b);
if(type == 1) add(b, a);
dout[a] ++ , din[b] ++ ;
}
// The situation that cannot constitute an eulato
if(type == 1){
// If it is wu Digraph
for(int i = 1; i <= n; i ++ ){
int t = din[i] + dout[i];
if(t & 1){
puts("NO");
return 0;
}
}
}
else{
// If it is you Digraph
for(int i = 1; i <= n; i ++ ){
if(din[i] != dout[i]){
puts("NO");
return 0;
}
}
}
// Can form an Euler chart , Deep search traversal output scheme
for(int i = 1; i <= n; i ++ ){
if(h[i] != -1){
dfs(i);
break; // Find a non isolated point and start traversing
}
}
if(cnt < m){
puts("NO");
return 0;
}
cout<<"YES"<<endl;
for(int i = cnt; i; i -- ){
cout<<ans[i]<<' ';
}
cout<<endl;
return 0;
}
边栏推荐
- TCP 滑动窗口详解(非常实用)
- Manual encapsulation object deep copy method
- AcWing 1184. 欧拉回路 题解(欧拉回路)
- GL_ TRIANGLE_ Fan and GL_ TRIANGLE_ STRIP
- Is it safe for Huatai Securities to open an account online, and can VIP accounts be handled
- Matlab natural spline function (constraining the slope at both ends)
- 这家初创公司想看看你的丁丁!他们用AI检测性疾病,保证数据匿名且加密,你愿意吗
- 网络IP地址子网划分学习
- 云呐|动环监控系统巡检,动环监控系统功能大致介绍
- 同花顺上面开户安全吗 reits基金怎么购买
猜你喜欢
Intelligent operation and maintenance scenario analysis: how to detect abnormal business system status through exception detection
X Book app digital beauty Sid analysis
unordered_ Use of map
智能运维场景解析:如何通过异常检测发现业务系统状态异常
Answer to the virtual configuration of network construction and application of 2021 national vocational college skills competition
关于SAP APO RPMCALL 指定生产订单的BOM更新
EN 1504-5混凝土结构保护和修理用产品混凝土喷射—CE认证
【Flutter -- 基础组件】单选开关(Switch)& 单选框(Radio) & 复选框(Checkbox)
Data analysis from 0 to 1 --- Matplotlib article
TCP 滑动窗口详解(非常实用)
随机推荐
2021年全国职业院校技能大赛网络搭建与应用之虚拟化配置答案
【红队】ATT&CK - Active Scanning(主动扫描)
AcWing 1124. 骑马修栅栏 题解(欧拉回路)
[unity3d] blood bar (HP)
美参议院初步通过520亿美元「芯片法案」,她竟乘机「投资炒股」!
路由策略-
SYSTEMd management process exporter
服裝ERP上線後,這些問題必須重視
MATLAB 自然样条函数(约束两端斜率)
我擦\那些测试员面试中的“潜规则”,千万不要踩坑
100万人排队在等!DALL·E公开测试版,还收上费了
【公开课预告】:云视频会议系统私有化实践
Chapter1 Beginning Bash
composer.json 常用配置解释
基于oracle数据库存储过程的创建及调用
The air conditioner in no man's land has poor refrigeration
什么是视频内容推荐引擎?
Common tools (Liu Xin)
机房动环监控系统的功能,动环监控系统的主要功能
在同花顺网上开户安全吗 国债逆回购怎么买