Problem Statement

You are given a simple connected undirected graph with $N$ vertices and $M$ edges. (A graph is said to be simple if it has no multi-edges and no self-loops.)

For $i = 1, 2, \ldots, M$, the $i$-th edge connects Vertex $u_i$ and Vertex $v_i$.

A sequence $(A_1, A_2, \ldots, A_k)$ is said to be a path of length $k$ if both of the following two conditions are satisfied:

  • For all $i = 1, 2, \dots, k$, it holds that $1 \leq A_i \leq N$.
  • For all $i = 1, 2, \ldots, k-1$, Vertex $A_i$ and Vertex $A_{i+1}$ are directly connected with an edge.

An empty sequence is regarded as a path of length $0$.

You are given a sting $S = s_1s_2\ldots s_N$ of length $N$ consisting of $0$ and $1$.
A path $A = (A_1, A_2, \ldots, A_k)$ is said to be a good path with respect to $S$ if the following conditions are satisfied:

  • For all $i = 1, 2, \ldots, N$, it holds that:
    • if $s_i = 0$, then $A$ has even number of $i$'s.
    • if $s_i = 1$, then $A$ has odd number of $i$'s.

Under the Constraints of this problem, it can be proved that there is at least one good path with respect to $S$ of length at most $4N$.
Print a good path with respect to $S$ of length at most $4N$.

Constraints

  • $2 \leq N \leq 10^5$
  • $N-1 \leq M \leq \min\lbrace 2 \times 10^5, \frac{N(N-1)}{2}\rbrace$
  • $1 \leq u_i, v_i \leq N$
  • The given graph is simple and connected.
  • $N, M, u_i$, and $v_i$ are integers.
  • $S$ is a string of length $N$ consisting of $0$ and $1$.

Input

Input is given from Standard Input in the following format:

$N$ $M$
$u_1$ $v_1$
$u_2$ $v_2$
$\vdots$
$u_M$ $v_M$
$S$

Output

Print a good path with respect to $S$ of length at most $4N$ in the following format.
Specifically, the first line should contain the length $K$ of the path, and the second line should contain the elements of the path, with spaces in between.

$K$
$A_1$ $A_2$ $\ldots$ $A_K$

Sample Input 1

6 6
6 3
2 5
4 2
1 3
6 5
3 2
110001

Sample Output 1

9
2 5 6 5 6 3 1 3 6

The path $(2, 5, 6, 5, 6, 3, 1, 3, 6)$ has a length no greater than $4N$, and

  • it has odd number ($1$) of $1$
  • it has odd number ($1$) of $2$
  • it has even number ($2$) of $3$
  • it has even number ($0$) of $4$
  • it has even number ($2$) of $5$
  • it has odd number ($3$) of $6$

so it is a good path with respect to $S = 110001$.


Sample Input 2

3 3
3 1
3 2
1 2
000

Sample Output 2

0

An empty path $()$ is a good path with respect to $S = 000000$.
Alternatively, paths like $(1, 2, 3, 1, 2, 3)$ are also accepted.

真的要图吗?可以尝试只经过图里面的一棵生成树

考虑数中序列节点相邻的在序列相邻是什么东西?欧拉环游序!

但是欧拉环游序的奇偶不一定正确,怎么办?

想一下如何改变一个位置的奇偶。可以先向他父亲走一步,然后走回来,然后再向父亲走,好像就满足了。

但是 1 没有父亲?

反正一开始都搜到了,在最后回去的时候,特判一下,不走就行了

#include<cstdio>
const int N=1e5+5;
int n,m,k,idx,a[N<<2],b[N<<2],f[N],t[N],fa[N],hd[N],e_num,u,v,c[N];
char s[N];
struct edge{
int v,nxt;
}e[N<<2];
void add_edge(int u,int v)
{
e[++e_num]=(edge){v,hd[u]};
hd[u]=e_num;
}
int find(int x)
{
if(fa[x]==x)
return x;
return fa[x]=find(fa[x]);
}
void dfs(int x,int y)
{
a[++idx]=x;
for(int i=hd[x];i;i=e[i].nxt)
{
if(e[i].v!=y)
{
dfs(e[i].v,x);
a[++idx]=x;
}
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
fa[i]=i;
for(int i=1;i<=m;i++)
{
scanf("%d%d",&u,&v);
if(find(u)!=find(v))
fa[find(u)]=find(v),add_edge(u,v),add_edge(v,u);
}
scanf("%s",s+1);
dfs(1,0);
for(int i=idx;i>=1;i--)
if(!t[a[i]])
t[a[i]]=1,f[i]=1;;
for(int i=1;i<idx;i++)
{
if(f[i])
if((c[a[i]]&1)==(s[a[i]]-'0'))
b[++k]=a[i],b[++k]=a[i+1],c[a[i+1]]++,c[a[i]]++;
b[++k]=a[i];
c[a[i]]++;
}
if((c[1]&1)!=(s[1]-'0'))
b[++k]=1;
printf("%d\n",k);
for(int i=1;i<=k;i++)
printf("%d ",b[i]);
}

[ABC244G] Construct Good Path的更多相关文章

  1. Path Creation and Path Painting

    [Path Creation and Path Painting] Path creation and path painting are separate tasks. First you crea ...

  2. imutils.path

    from imutils import paths # 要在哪条路径下查找 path = '...' # 查找图片,得到图片路径 imagePaths = list(imutils.paths.lis ...

  3. alfresco category searches...

    From page 475 of the Alfresco Developer Guide- Category searches use the PATH field, but you constru ...

  4. ArrowLayer : A coustom layer animation

    Since my other answer (animating two levels of masks) has some graphics glitches, I decided to try r ...

  5. Java fundamentals of basic IO

    IO is a problem difficult to handle in various of systems because it  always becomes a bottleneck in ...

  6. react native mac install

    Mac上使用react native tips: 1. 安装Homebrew ruby -e "$(curl -fsSL https://raw.githubusercontent.com/ ...

  7. boost操作xml 5分钟官方教程

    Five Minute Tutorial This tutorial uses XML. Note that the library is not specifically bound to XML, ...

  8. Device trees, Overlays and Parameters of Raspberry Pi

    Raspberry Pi's latest kernels and firmware, including Raspbian and NOOBS releases, now by default us ...

  9. hdfs api读写文写件个人练习

    看下hdfs的读写原理,主要是打开FileSystem,获得InputStream or OutputStream: 那么主要用到的FileSystem类是一个实现了文件系统的抽象类,继承来自org. ...

  10. Android測试环境变量配置表

    要改动的文件是~/bash_profile这个配置文件,内容例如以下: # Setting PATH for Java JAVA_HOME="/Library/Java/JavaVirtua ...

随机推荐

  1. [ABC305D] Sleep Log题解

    题目大意 给 \(N\) 个时刻: 当 \(i\) 为奇数时,\(A_i\) 表示刚刚起床的时刻. 当 \(i\) 为偶数时,\(A_i\) 表示开始睡觉的时刻. 有 \(Q\) 次询问,每次求在 \ ...

  2. 安装iTerm2和oh-my-zsh

    安装iTerm2和oh-my-zsh 此文是在参考许多教程(见目录:参考)并结合本人安装经历写下的一篇关于iTerm2和oh-my-zsh的认识和超级详细安装教程.全文所有图片均为本人截屏拍摄.希望能 ...

  3. mysql到底需不需要容器化?

    前言:在容器化的时代,当然一切皆可容器化.在docker官网首页赫然有下面这几个大字.足以知道docker的优势.那么且问,mysql适合跑在docker中吗? 当然,这个问题有人说可以,也有人说不可 ...

  4. 应用程序通过 Envoy 代理和 Jaeger 进行分布式追踪 —— Ingress Controller + Http服务 + Grpc服务(三)

    1.概述 在<应用程序通过 Envoy 代理和 Jaeger 进行分布式追踪(一)>这篇博文中,我们详细介绍了单个应用程序通过 Envoy 和 Jaeger 实现链路追踪的过程.通过这个示 ...

  5. ArcMap中矢量数据修改标注Label的方法

      本文介绍在ArcMap软件中,修改图层标签(Label)所显示字段与具体显示内容的方法.   在之前的文章中,我们看到了ArcMap中修改图层标签的重要性:可是,如何自定义图层的标签内容呢?    ...

  6. [TSG开发日志](一)软件基础框架

    目录 前言 说明 框架 TSG_Framework 一.底层信号机制 TSG_Caller 二.参数类型声明 TSG_Params 三.设备类声明 TSG_Device 四.设备配置文件控制 TSG_ ...

  7. 搭建企业知识库:基于 Wiki.js 的实践指南

    一.简介 在当今知识经济时代,企业知识库的建设变得越来越重要.它不仅有助于企业知识的沉淀和共享,还能提升员工的工作效率,促进企业的创新发展.企业知识库是企业中形成结构化文档,共享知识的集群,可以促进企 ...

  8. 工作中常用的一些Git骚操作,一般人我不告诉他。

    一.Git提交代码 1 git pull 从服务器上拉取代码 2 git status 查看文件的状态 3 git add . 添加所有文件到暂存区 4 git commit -m "提交的 ...

  9. IP协议的发展历程

    1. IP协议 1.1为什么需要IP协议 好像ip地址就像每个人的家门号一样家喻户晓,被大家默认用来作为寻址的门牌号,起初,设计IP地址也是为了寻找某台主机,但是作为世界上家喻户晓的IPv4,大家不应 ...

  10. 前端框架——Vue2

    文章目录 初识Vue 模板语法 数据绑定 el与data的两种写法 理解MVVM 数据代理 事件处理 计算属性 监视属性 绑定样式 条件渲染 列表渲染 收集表单数据 过滤器 内置指令 自定义指令 生命 ...