当前位置:网站首页>Cf1494f delete the edges (Euler circuit)
Cf1494f delete the edges (Euler circuit)
2022-07-26 00:53:00 【wind__ whisper】
Preface
Go far go far …
I've been thinking about how to flip the parity of a chain , But I didn't realize that it must be a chrysanthemum in the end .
analysis
One state is to take an Euler loop , Legitimacy is easier to portray , So consider thinking in reverse , How to delete some edges with the walking method of state two , Make the remaining graph exist Euler path .
So what is the walking method of state two ?
Because the edge must be deleted at last , Perceptual understanding , The picture of state 2 going out must be a chrysanthemum .
So just discuss each point directly as the chrysanthemum Center . Because the rest of the diagram may not be connected , It also needs to be legal to run Euler road violently .
Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define ok debug("ok\n")
inline ll read(){
ll x(0),f(1);char c=getchar();
while(!isdigit(c)){
if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){
x=(x<<1)+(x<<3)+c-'0';c=getchar();}
return x*f;
}
const int N=6050;
const int mod=998244353;
ll n,m,k;
inline ll ksm(ll x,ll k,int mod){
ll res(1);
while(k){
if(k&1) res=x*res%mod;
x=x*x%mod;
k>>=1;
}
return res;
}
struct node{
int to,nxt,id;
}p[N<<1];
int fi[N],cur[N],ecnt;
inline void addline(int x,int y,int id){
p[++ecnt]=(node){
y,fi[x],id};fi[x]=ecnt;
return;
}
int zhan[N],top;
int du[N];
bool vis[N];
void dfs(int x){
//debug("x=%d\n",x);
for(int i=cur[x];~i;i=cur[x]){
cur[x]=p[i].nxt;
if(vis[p[i].id]) continue;
vis[p[i].id]=1;
dfs(p[i].to);
}
zhan[++top]=x;
}
void init(){
for(int i=1;i<=n;i++) cur[i]=fi[i];
memset(vis,0,sizeof(vis));
top=0;
}
int cnt,rt;
inline void calc(int x,int ban,int e){
init();
--e;
for(int i=fi[x];~i;i=p[i].nxt){
int to=p[i].to;
if(!(du[to]&1)) continue;
if(to==ban) continue;
vis[p[i].id]=1;
}
dfs(x);
if(top-1+e==m){
printf("%d\n",top+1+2*e);
for(int i=1;i<=top;i++) printf("%d ",zhan[i]);
printf("-1 ");
for(int i=fi[x];~i;i=p[i].nxt){
int to=p[i].to;
if(to==ban) continue;
if(du[to]&1) printf("%d %d ",to,x);
}
exit(0);
}
}
inline void work(int x){
int num=du[x]&1,e(0);
for(int i=fi[x];~i;i=p[i].nxt){
int to=p[i].to;
num+=(du[to]&1);
e+=(du[to]&1);
}
if(num==cnt){
for(int i=fi[x];~i;i=p[i].nxt){
int to=p[i].to;
if(du[to]&1) calc(x,to,e);
}
}
if(num>=cnt-1){
init();
//ok;
for(int i=fi[x];~i;i=p[i].nxt){
int to=p[i].to;
if(du[to]&1) vis[p[i].id]=1;
}
dfs(x);
if(top-1+e==m){
//printf("top=%d e=%d\n",top,e);
printf("%d\n",top+1+2*e);
for(int i=1;i<=top;i++) printf("%d ",zhan[i]);
printf("-1 ");
for(int i=fi[x];~i;i=p[i].nxt){
int to=p[i].to;
if(du[to]&1) printf("%d %d ",to,x);
}
exit(0);
}
}
return;
}
signed main(){
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
memset(fi,-1,sizeof(fi));ecnt=-1;
cnt=-1;
n=read();m=read();
for(int i=1;i<=m;i++){
int x=read(),y=read();
addline(x,y,i);
addline(y,x,i);
du[x]++;
du[y]++;
}
cnt=0,rt=1;
for(int i=1;i<=n;i++){
if(du[i]&1){
++cnt;
rt=i;
}
}
if(cnt<=2){
init();
dfs(rt);
printf("%d\n",top);
while(top) printf("%d ",zhan[top--]);
return 0;
}
for(int i=1;i<=n;i++) work(i);
puts("0");
return 0;
}
/* */
边栏推荐
- HCIP第十三天
- [calculate the number of times that one string is equal to another string]
- 【RTOS训练营】关于上课和答疑
- With data-driven management transformation, the first year of science and technology was at the right time
- User defined variables and extracted public variables of JMeter
- Analysis and practice of parameter parser handlermethodargumentresolver
- JDBC implements the addition, deletion, modification and query of MySQL 8.0 database
- [RTOS training camp] operation explanation, queue and ring buffer, queue - transmission data, queue - synchronization tasks and evening class questions
- Hnoi2012 mine construction
- Oauth2 and JWT
猜你喜欢

AI knows everything: build and deploy sign language recognition system from 0

Hcip day 11

JDBC实现MySQL8.0数据库的增删改查

With data-driven management transformation, the first year of science and technology was at the right time

The ultra comprehensive open source WinForm UI library meets all your desktop development needs!

用 QuestPDF操作生成PDF更快更高效!

聊聊研发团队中的“人”

200 yuan a hair dryer, only a week, to achieve 2million?

The task will be launched before the joint commissioning of development

Master MySQL in an article
随机推荐
【RTOS训练营】关于上课和答疑
Use localdate class to complete calendar design
【RTOS训练营】课程学习方法和C语言知识(指针、结构体、函数指针、链表)和学员问题
Nodejs learning
开发还没联调,任务就要上线
测试左移和测试右移的概念
HCIP第十三天
[RTOS training camp] equipment subsystem, questions of evening students
Open download! Alibaba Devops Practice Manual
sql语句练习
The task will be launched before the joint commissioning of development
分布式事务和Seata的AT模式原理
HCIP 第十一天
Prefix XOR sum, XOR difference array
Travel + strategy accelerated landing, jietu new product matrix exposure
[RTOS training camp] review of the previous section, idle tasks, timer tasks, execution sequence, scheduling strategy and evening class questions
GOM and GEE engine black screen does not display the interface, and the solution of equipping map monsters
[untitled] how to realize pluggable configuration?
Amin's confession
Hcip day 11