当前位置:网站首页>AcWing 1124. Solution to the problem of repairing fences on horseback (Euler circuit)
AcWing 1124. Solution to the problem of repairing fences on horseback (Euler circuit)
2022-07-22 11:17:00 【QingQingDE23】
AcWing 1124. Riding a horse to mend the fence
What needs to be remembered is why ans To output in reverse order , And how to search according to the scheme with the smallest dictionary order
Big guy problem solving original address
#include<bits/stdc++.h>
using namespace std;
const int N = 510, M = 1100;
int g[N][N];
int ans[M];
int n = 500, m;
int cnt;
int din[N];
void dfs(int u) {
for(int i = 1; i <= n; i ++ ){
if(g[u][i]){
g[u][i] -- ;
g[i][u] -- ;
dfs(i);
}
}
ans[ ++ cnt] = u;
}
int main()
{
cin>>m;
while(m -- ){
int a, b;
cin>>a>>b;
g[a][b] ++ ;
g[b][a] ++ ;
din[a] ++ ;
din[b] ++ ;
}
int start = 1;
while(!din[start]) start ++ ; // Find the first existing point start
for(int i = 1; i <= n; i ++ ){
if(din[i] % 2){
// In an undirected graph, only points with odd degrees can be used as starting points
start = i;
break;
}
}
dfs(start);
for(int i = cnt; i; i -- ) cout<<ans[i]<<endl;
return 0;
}
边栏推荐
- Keyframesextractutils Py, dynamically supports three framing methods, key parameters can be configured, and the code has been optimized for better effect and performance.
- Paste in ckeditor does not work (your browser does not support pasting through the toolbar or right-click menu, please press ctrl+v to paste)
- 同花顺上面开户安全吗 reits基金怎么购买
- 网络IP地址子网划分学习
- [cloud native | learn kubernetes from scratch] VII. Resource list and namespace
- 向量化引擎对HTAP的价值与技术思考
- Example interview - Zeng yuluo: gain experience from lectures
- 1million people are waiting in line! The public beta version of Dall · e is also charged
- 基于oracle数据库存储过程的创建及调用
- ADVANCE.AI:目前进入拉美地区的中国企业还较少,值得探索
猜你喜欢
ADVANCE.AI:目前进入拉美地区的中国企业还较少,值得探索
unordered_map的使用
BGP-边界网关协议
利用Kaggle的API对数据集进行下载
Creation and call of stored procedure based on Oracle Database
[public class preview]: cloud video conference system privatization practice
C. Doremy‘s IQ(贪心)
How to get the Apache official domain name mailbox? Exclusive interview with five new committers of Apache linkis
什么是单页面应用程序
Intelligent operation and maintenance scenario analysis: how to detect abnormal business system status through exception detection
随机推荐
美参议院初步通过520亿美元「芯片法案」,她竟乘机「投资炒股」!
Network IP address subnet partition learning
Data analysis from 0 to 1 --- Matplotlib article
Chapter1 Beginning Bash
BGP-边界网关协议
[10:00 public class]: cloud video conference system privatization practice
2022 audio and video technology vane
Dokcer运行Nacos容器自动退出问题
unordered_ Use of map
[public class preview]: cloud video conference system privatization practice
【公开课预告】:云视频会议系统私有化实践
composer.json 常用配置解释
Meta最新图像生成工具火了,竟能把梦境画成现实!
Time magazine's blockbuster cover: the meta universe era will change the world
易基因 | 简化基因组DNA甲基化测序(RRBS)实验怎么做?
在同花顺网上开户安全吗 国债逆回购怎么买
[cloud native | learn kubernetes from scratch] VII. Resource list and namespace
权限管理系列-1:权限管理介绍 — 对模块控制
模型微调(fine-tuning)
TypeScript—快速入门