#include <iostream>
#include <cstring>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <deque>
#include <bitset>
#include <algorithm>

using namespace std;

const double eps=1e-10;
const double pi=3.1415926535897932384626433832795;
const double eln=2.718281828459045235360287471352;

#define LL long long
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define scan(x) scanf("%d", &x)
#define scan2(x, y) scanf("%d%d", &x, &y)
#define scan3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define sqr(x) (x) * (x)
#define pr(x) printf("Case %d: ",x)
#define prn(x) printf("Case %d:\n",x)
#define prr(x) printf("Case #%d: ",x)
#define prrn(x) printf("Case #%d:\n",x)
#define lowbit(x) (x&(-x))

const int maxn=200005;

vector<int> g[maxn];
int fat[maxn];
vector<int> son[maxn];
int now[maxn];
bool has[maxn];
int i,j,k,l,m,n;
queue<int> q;

void DFS(int x,int y)
{
    fat[x]=y;
    if(now[x]<0)has[x]=true;
    for(unsigned int i=0;i<g[x].size();i++)
    {
        int v=g[x][i];
        if(fat[v]!=0)continue;
        son[x].push_back(v);
        DFS(v,x);
        if(now[v]<0 || has[v])has[x]=true;
    }
}

void find(int x)
{
    q.push(x);
    if(x>1)now[x]=-now[x];
    if(son[x].size()==0){has[x]=false;return;}
    for(unsigned int i=0;i<son[x].size();i++)
    {
        int v=son[x][i];
        if(has[v]){find(v);now[x]=-now[x];q.push(x);}
    }
    for(unsigned int i=0;i<son[x].size();i++)
    {
        int v=son[x][i];
        if(has[v]){find(v);now[x]=-now[x];q.push(x);}
    }
    if(now[x]<0)has[x]=true;else has[x]=false;
    if(x==1 && has[x])
    {
        q.push(son[1][0]);
        q.push(x);
        q.push(son[1][0]);
    }
}

int main()
{
    scanf("%d",&n);
    memset(has,0,sizeof(has));
    for(i=1;i<=n;i++)scanf("%d",&now[i]);
    for(i=1;i<=n-1;i++)
    {
        scan2(j,k);
        g[j].push_back(k);
        g[k].push_back(j);
    }
    DFS(1,-1);
    while(!q.empty())q.pop();
    find(1);n=0;
    while(!q.empty())
    {
        m=q.front();
        q.pop();
        if(m==0)continue;
        n++;
        if(n>1)printf(" ");
        printf("%d",m);
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <deque>
#include <bitset>
#include <algorithm>

using namespace std;

const double eps=1e-10;
const double pi=3.1415926535897932384626433832795;
const double eln=2.718281828459045235360287471352;

#define LL long long
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define scan(x) scanf("%d", &x)
#define scan2(x, y) scanf("%d%d", &x, &y)
#define scan3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define sqr(x) (x) * (x)
#define pr(x) printf("Case %d: ",x)
#define prn(x) printf("Case %d:\n",x)
#define prr(x) printf("Case #%d: ",x)
#define prrn(x) printf("Case #%d:\n",x)
#define lowbit(x) (x&(-x))

const int maxn=200005;

vector<int> g[maxn];
int fat[maxn];
vector<int> son[maxn];
int now[maxn];
bool has[maxn];
int i,j,k,n;

struct hi
{
    int num;
    void push(int t)
    {
        num++;
        if(num>1)printf(" ");
        printf("%d",t);
    }
}q;

void DFS(int x,int y)
{
    fat[x]=y;
    if(now[x]<0)has[x]=true;
    for(unsigned int i=0;i<g[x].size();i++)
    {
        int v=g[x][i];
        if(fat[v]!=0)continue;
        son[x].push_back(v);
        DFS(v,x);
        if(now[v]<0 || has[v])has[x]=true;
    }
}

void find(int x)
{
    q.push(x);
    if(x>1)now[x]=-now[x];
    if(son[x].size()==0){has[x]=false;return;}
    for(unsigned int i=0;i<son[x].size();i++)
    {
        int v=son[x][i];
        if(has[v]){find(v);now[x]=-now[x];q.push(x);}
    }
    for(unsigned int i=0;i<son[x].size();i++)
    {
        int v=son[x][i];
        if(has[v]){find(v);now[x]=-now[x];q.push(x);}
    }
    if(now[x]<0)has[x]=true;else has[x]=false;
    if(x==1 && has[x])
    {
        q.push(son[1][0]);
        q.push(x);
        q.push(son[1][0]);
    }
}

int main()
{
    scanf("%d",&n);
    memset(has,0,sizeof(has));
    for(i=1;i<=n;i++)scanf("%d",&now[i]);
    for(i=1;i<=n-1;i++)
    {
        scan2(j,k);
        g[j].push_back(k);
        g[k].push_back(j);
    }
    DFS(1,-1);
    q.num=0;
    find(1);n=0;
    return 0;
}


#include <iostream>
#include <cstring>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <deque>
#include <bitset>
#include <algorithm>

using namespace std;

const double eps=1e-10;
const double pi=3.1415926535897932384626433832795;
const double eln=2.718281828459045235360287471352;

#define LL long long
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
#define scan(x) scanf("%d", &x)
#define scan2(x, y) scanf("%d%d", &x, &y)
#define scan3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define sqr(x) (x) * (x)
#define pr(x) printf("Case %d: ",x)
#define prn(x) printf("Case %d:\n",x)
#define prr(x) printf("Case #%d: ",x)
#define prrn(x) printf("Case #%d:\n",x)
#define lowbit(x) (x&(-x))

const int maxn=200005;

vector<int> g[maxn];
int fat[maxn];
vector<int> son[maxn];
int now[maxn];
bool has[maxn];
int i,j,k,l,m,n;
queue<int> q;

void DFS(int x,int y)
{
    fat[x]=y;
    if(now[x]<0)has[x]=true;
    for(unsigned int i=0;i<g[x].size();i++)
    {
        int v=g[x][i];
        if(fat[v]!=0)continue;
        son[x].push_back(v);
        DFS(v,x);
        if(now[v]<0 || has[v])has[x]=true;
    }
}

void find(int x)
{
    q.push(x);
    now[x]=-now[x];
    if(son[x].size()==0){has[x]=false;return;}
    for(unsigned int i=0;i<son[x].size();i++)
    {
        int v=son[x][i];
        if(has[v]){find(v);now[x]=-now[x];q.push(x);}
    }
    for(unsigned int i=0;i<son[x].size();i++)
    {
        int v=son[x][i];
        if(has[v]){find(v);now[x]=-now[x];q.push(x);}
    }
    if(now[x]<0)has[x]=true;else has[x]=false;
}

int main()
{
    scanf("%d",&n);
    memset(has,0,sizeof(has));
    for(i=1;i<=n;i++)scanf("%d",&now[i]);
    for(i=1;i<=n-1;i++)
    {
        scan2(j,k);
        g[j].push_back(k);
        g[k].push_back(j);
    }
    DFS(1,-1);
    while(!q.empty())q.pop();
    now[1]=-now[1];
    if(now[1]<0)has[1]=true;else has[1]=false;
    fat[1]=0;now[0]=0;son[0].push_back(1);
    find(0);n=0;
    while(!q.empty())
    {
        m=q.front();
        q.pop();
        if(m==0)continue;
        n++;
        if(n>1)printf(" ");
        printf("%d",m);
    }
    return 0;
}


#include <bits/stdc++.h>
#define N 200005
#define M 400005

using namespace std;
inline int read(){
	int ret=0;char ch=getchar();
	bool flag=0;
	while (ch<'0'||ch>'9'){
		flag=ch=='-';
		ch=getchar();
	}
	while ('0'<=ch&&ch<='9'){
		ret=ret*10-48+ch;
		ch=getchar();
	}
	return flag?-ret:ret;
}

int sum;
struct edge{
	int adj,next;
	edge(){}
	edge(int _adj,int _next):adj(_adj),next(_next){}
} e[M];
int n,g[N],m;
void AddEdge(int u,int v){
	e[++m]=edge(v,g[u]);g[u]=m;
	e[++m]=edge(u,g[v]);g[v]=m;
}

bool col[N];
int size[N];
int fa[N];
void dfs0(int u){
	for (int i=g[u];i;i=e[i].next){
		int v=e[i].adj;
		if (v==fa[u]) continue;
		fa[v]=u;
		dfs0(v);
		size[u]+=size[v];
	}
}

int dfs(int u){
//	printf("%d %d\n",u,sum);
	printf("%d ",u);
	int ret=0;
	if (!size[u]) return ret;
	for (int i=g[u];i;i=e[i].next){
		int v=e[i].adj;
		if (v==fa[u]) continue;
		while (size[v]){
			ret+=col[v]*2-1;
			size[v]-=col[v]*2-1;
			sum-=col[v]*2-1;
			col[v]^=1;

			ret+=dfs(v);
			if (!sum) return ret;

			ret+=col[u]*2-1;
			sum-=col[u]*2-1;
			col[u]^=1;
			printf("%d ",u);
//			printf("%d %d\n",u,sum);
		}
		if (!sum) return ret;
	}
	size[u]-=ret;
	return ret;
}

int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	n=read();
	for (int i=1;i<=n;++i) size[i]=col[i]=read()<0;
	memset(g,0,sizeof(g));m=1;
	for (int i=1;i<n;++i) AddEdge(read(),read());
	fa[1]=0;
	dfs0(1);
	sum=size[1];
	dfs(1);
	if (sum){
		int x=e[g[1]].adj;
		printf("%d %d %d",x,1,x);
	}
	puts("");
	return 0;
}


#include <bits/stdc++.h>
#define N 200005
#define M 400005

using namespace std;
inline int read(){
	int ret=0;char ch=getchar();
	bool flag=0;
	while (ch<'0'||ch>'9'){
		flag=ch=='-';
		ch=getchar();
	}
	while ('0'<=ch&&ch<='9'){
		ret=ret*10-48+ch;
		ch=getchar();
	}
	return flag?-ret:ret;
}

int sum;
struct edge{
	int adj,next;
	edge(){}
	edge(int _adj,int _next):adj(_adj),next(_next){}
} e[M];
int n,g[N],m;
void AddEdge(int u,int v){
	e[++m]=edge(v,g[u]);g[u]=m;
	e[++m]=edge(u,g[v]);g[v]=m;
}

bool col[N];
int size[N];
int fa[N];
void dfs0(int u){
	for (int i=g[u];i;i=e[i].next){
		int v=e[i].adj;
		if (v==fa[u]) continue;
		fa[v]=u;
		dfs0(v);
		size[u]+=size[v];
	}
}

int dfs(int u){
//	printf("%d %d\n",u,sum);
	printf("%d ",u);
	int ret=0;
	if (!size[u]) return ret;
	for (int i=g[u];i;i=e[i].next){
		int v=e[i].adj;
		if (v==fa[u]) continue;
		while (size[v]){
			ret+=col[v]*2-1;
			size[v]-=col[v]*2-1;
			sum-=col[v]*2-1;
			col[v]^=1;

			ret+=dfs(v);
			if (!sum) return ret;

			ret+=col[u]*2-1;
			sum-=col[u]*2-1;
			col[u]^=1;
			printf("%d ",u);
//			printf("%d %d\n",u,sum);
		}
		if (!sum) return ret;
	}
	size[u]-=ret;
	return ret;
}

int main(){
	n=read();
	for (int i=1;i<=n;++i) size[i]=col[i]=read()<0;
	memset(g,0,sizeof(g));m=1;
	for (int i=1;i<n;++i) AddEdge(read(),read());
	fa[1]=0;
	dfs0(1);
	sum=size[1];
	dfs(1);
	puts("");
	return 0;
}


#include <bits/stdc++.h>
#define N 200005
#define M 400005

using namespace std;
inline int read(){
	int ret=0;char ch=getchar();
	bool flag=0;
	while (ch<'0'||ch>'9'){
		flag=ch=='-';
		ch=getchar();
	}
	while ('0'<=ch&&ch<='9'){
		ret=ret*10-48+ch;
		ch=getchar();
	}
	return flag?-ret:ret;
}

int sum;
struct edge{
	int adj,next;
	edge(){}
	edge(int _adj,int _next):adj(_adj),next(_next){}
} e[M];
int n,g[N],m;
void AddEdge(int u,int v){
	e[++m]=edge(v,g[u]);g[u]=m;
	e[++m]=edge(u,g[v]);g[v]=m;
}

bool col[N];
int size[N];
int fa[N];
void dfs0(int u){
	for (int i=g[u];i;i=e[i].next){
		int v=e[i].adj;
		if (v==fa[u]) continue;
		fa[v]=u;
		dfs0(v);
		size[u]+=size[v];
	}
}

int dfs(int u){
//	printf("%d %d\n",u,sum);
	printf("%d ",u);
	int ret=0;
	if (!size[u]) return ret;
	for (int i=g[u];i;i=e[i].next){
		int v=e[i].adj;
		if (v==fa[u]) continue;
		while (size[v]){
			ret+=col[v]*2-1;
			size[v]-=col[v]*2-1;
			sum-=col[v]*2-1;
			col[v]^=1;

			ret+=dfs(v);
//			if (!sum) return ret;

			ret+=col[u]*2-1;
			sum-=col[u]*2-1;
			col[u]^=1;
			printf("%d ",u);
//			printf("%d %d\n",u,sum);
		}
//		if (!sum) return ret;
	}
	size[u]-=ret;
	return ret;
}

int main(){
	n=read();
	for (int i=1;i<=n;++i) size[i]=col[i]=read()<0;
	memset(g,0,sizeof(g));m=1;
	for (int i=1;i<n;++i) AddEdge(read(),read());
	fa[1]=0;
	dfs0(1);
	sum=size[1];
	dfs(1);
	puts("");
	return 0;
}


#include<cstdio>
struct edge{int to,next;}e[400005];
int head[400001],cnt,n,x,y,c[400005];
void add(int x,int y){e[++cnt].to=y,e[cnt].next=head[x],head[x]=cnt;}
void dfs(int x,int fa)
{
	for (int i=head[x]; i; i=e[i].next)
	{
		int to=e[i].to;
		if (to==fa) continue;
		printf("%d ",to);
		c[to]=-c[to];
		dfs(to,x);
		c[x]=-c[x];
		printf("%d ",x);
		if (c[to]==-1)
		{
			c[to]=-c[to];
			c[x]=-c[x];
			printf("%d %d ",to,x);
		}
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
		scanf("%d",&c[i]);
	for (int i=1; i<n; i++)
		scanf("%d%d",&x,&y),add(x,y),add(y,x);
	printf("1 ");
	dfs(1,0);
	if (c[1]==-1)
	{
		int to=e[head[1]].to;
		printf("%d 1 %d",to,to);
	}
}


#include<cstdio>
struct edge{int to,next;}e[400005];
int head[400001],cnt,n,x,y,c[400005];
void add(int x,int y){e[++cnt].to=y,e[cnt].next=head[x],head[x]=cnt;}
void dfs(int x,int fa)
{
	for (int i=head[x]; i; i=e[i].next)
	{
		int to=e[i].to;
		if (to==fa) continue;
		printf("%d ",to);
		c[to]=-c[to];
		dfs(to,x);
		c[x]=-c[x];
		printf("%d ",x);
		if (c[to]==-1)
		{
			c[to]=-c[to];
			c[x]=-c[x];
			printf("%d %d ",to,x);
		}
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
		scanf("%d",&c[i]);
	for (int i=1; i<n; i++)
		scanf("%d%d",&x,&y),add(x,y),add(y,x);
	printf("1 ");
	dfs(1,0);
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<vector>
using namespace std;

#define maxn 1000100
vector<int> g[maxn],ans;
int a[maxn];
int n;

void dfs(int v,int p)
{
	for(int i=0;i<g[v].size();i++)
	{
		int u=g[v][i];
		if (u==p) continue;
		a[u]^=1;
		ans.push_back(u);
		dfs(u,v);
		a[v]^=1;
		ans.push_back(v);
		if (!a[u])
		{
			a[u]^=1;
			ans.push_back(u);
			a[v]^=1;
			ans.push_back(v);
		}
	}
	if (v==1 && !a[v])
	{
		int u=g[v][0];
		a[u]^=1;
		ans.push_back(u);
		a[v]^=1;
		ans.push_back(v);
		a[u]^=1;
		ans.push_back(u);
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",a+i);
		if (a[i]==-1) a[i]=0;
	}
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	ans.push_back(1);
	dfs(1,0);
	for(int i=0;i<ans.size();i++)
		printf("%d ",ans[i]);
	puts("");
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<vector>
using namespace std;

#define maxn 1000100
vector<int> g[maxn],ans;
int a[maxn];
int n;

void dfs(int v,int p)
{
	for(int i=0;i<g[v].size();i++)
	{
		int u=g[v][i];
		if (u==p) continue;
		ans.push_back(u);
		dfs(u,v);
		ans.push_back(v);
		if (!a[u])
		{
			ans.push_back(u);
			ans.push_back(v);
		}
	}
	if (v==1 && !a[v])
	{
		int u=g[v][0];
		ans.push_back(u);
		ans.push_back(v);
		ans.push_back(u);
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",a+i);
		if (a[i]==-1) a[i]=0;
	}
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	ans.push_back(1);
	dfs(1,0);
	for(int i=0;i<ans.size();i++)
		printf("%d ",ans[i]);
	puts("");
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n,col[SZ];
Edg
int oo[SZ],on=0;
void dfs(int x,int f)
{
	oo[++on]=x; col[x]^=1;
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		dfs(b,x);
	}
	oo[++on]=x; col[x]^=1;
	if(col[x]&&x!=1)
	{
	oo[++on]=f;
	oo[++on]=x; col[x]^=1;
	oo[++on]=f;
	}
}
int main()
{
	scanf("%d",&n);
	int cc=0,p;
	for(int i=1;i<=n;i++)
	scanf("%d",col+i), col[i]=col[i]<0, cc+=col[1];
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d%d",&a,&b);
		if(a>b) swap(a,b);
		if(a==1) p=b;
		adde(a,b);
	}
	if(cc==1&&col[1])
	{
		printf("1 %d 1 %d\n",p,p);
		return 0;
	}
	dfs(1,0);
	if(!col[1])
	{
		if(oo[on]==1) --on;
		else oo[++on]=1;
	}
	for(int i=1;i<=on;i++) printf("%d ",oo[i]);
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n,col[SZ];
Edg
int fa[SZ];
void dfs(int x,int f)
{
	fa[x]=f;
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		dfs(b,x);
	}
}
int ss[SZ],sn=0;
int oo[133333330],on=0;
map<int,bool> rp[2333];
int pm[SZ];
int main()
{
	scanf("%d",&n);
	int cc=0;
	//for(int i=1;i<=n;i++) col[i]=0;
	//col[1]=1;
	//for(int i=1;i<=n;i++) pm[i]=i;
	//random_shuffle(pm+1,pm+1+n);
	for(int i=1;i<=n;i++)
	scanf("%d",col+i), col[i]=col[i]<0;
	for(int i=1;i<=n;i++) cc+=col[i];
	int p=0;
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d%d",&a,&b);
		//a=rand()%i+1; b=i+1;
		if(a>b) swap(a,b);
		if(a==1) p=b;
		//a=pm[a]; b=pm[b];
		//rp[a][b]=rp[b][a]=1;
		adde(a,b);
	}
	if(cc==1&&col[1])
	{
		printf("1 %d 1 %d\n",p,p);
		return 0;
	}
	dfs(1,0);
	int t=0;
	for(int i=2;i<=n;i++)
	{
		if(col[i])
		{
			sn=0; int cur=i;
			while(cur!=1) ss[++sn]=cur, cur=fa[cur];
			if(t&1);else oo[++on]=1;
			for(int i=sn;i>=1;i--) oo[++on]=ss[i];
			for(int i=2;i<=sn;i++) oo[++on]=ss[i];
			if(t&1);else oo[++on]=1;
			++t;
		}
	}
	if(!col[1])
	{
		if(oo[on]==1) --on;
		else oo[++on]=1;
	}
	for(int i=1;i<=on;i++) printf("%d ",oo[i]);
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n,col[SZ];
Edg
int oo[SZ],on=0;
void dfs(int x,int f)
{
	oo[++on]=x; col[x]^=1;
	bool down=0;
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		dfs(b,x); oo[++on]=x, col[x]^=1;
	}
	if(col[x]&&x!=1)
	{
	oo[++on]=f;
	oo[++on]=x; col[x]^=1;
	oo[++on]=f;
	}
}
int main()
{
	scanf("%d",&n);
	int cc=0,p;
	for(int i=1;i<=n;i++)
	scanf("%d",col+i), col[i]=col[i]<0, cc+=col[1];
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d%d",&a,&b);
		if(a>b) swap(a,b);
		if(a==1) p=b;
		adde(a,b);
	}
	if(cc==1&&col[1])
	{
		printf("1 %d 1 %d\n",p,p);
		return 0;
	}
	dfs(1,0);
	if(!col[1])
	{
		if(oo[on]==1) --on;
		else oo[++on]=1;
	}
	for(int i=1;i<=on;i++) printf("%d ",oo[i]);
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n,col[SZ];
Edg
int qj[SZ],fa[SZ];
bool safe[SZ];
void dfs(int x,int f)
{
	fa[x]=f; qj[x]=0;
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		dfs(b,x); qj[x]|=qj[b]|col[b];
	}
	safe[x]=!(qj[x]&&col[x]);
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		safe[x]&=safe[b];
	}
}
void dfs2(int x,int f)
{
	if(!col[x]&&!qj[x]) return;
	printf("%d ",x);
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		if(!col[b]&&!qj[b]) continue;
		if(safe[b]) dfs2(b,x);
		if(safe[x]) printf("%d ",x);
	}
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		if(!col[b]&&!qj[b]) continue;
		if(!safe[b]) dfs2(b,x);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",col+i), col[i]=col[i]<0;
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d%d",&a,&b);
		adde(a,b);
	}
	dfs(1,0);
	dfs2(1,0);
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n,col[SZ];
Edg
int fa[SZ];
void dfs(int x,int f)
{
	fa[x]=f;
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		dfs(b,x);
	}
}
int ss[SZ],sn=0;
vector<int> oo;
map<int,bool> rp[2333];
int pm[SZ];
int main()
{
	scanf("%d",&n);
	int cc=0;
	for(int i=1;i<=n;i++)
	scanf("%d",col+i), col[i]=col[i]<0;
	for(int i=1;i<=n;i++) cc+=col[i];
	int p=0;
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d%d",&a,&b);
		if(a>b) swap(a,b);
		if(a==1) p=b;
		adde(a,b);
	}
	if(cc==1&&col[1])
	{
		printf("1 %d 1 %d\n",p,p);
		return 0;
	}
	dfs(1,0);
	int t=0;
	for(int i=2;i<=n;i++)
	{
		if(col[i])
		{
			sn=0; int cur=i;
			while(cur!=1) ss[++sn]=cur, cur=fa[cur];
			if(t&1);else oo.push_back(1);
			for(int i=sn;i>=1;i--) oo.push_back(ss[i]);
			for(int i=2;i<=sn;i++) oo.push_back(ss[i]);
			if(t&1);else oo.push_back(1);
			++t;
		}
	}
	if(!col[1])
	{
		if(oo[oo.size()-1]==1) oo.pop_back();
		else oo.push_back(1);
	}
	for(int i=0;i<oo.size();i++) printf("%d ",oo[i]);
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n,col[SZ];
Edg
int fa[SZ];
void dfs(int x,int f)
{
	fa[x]=f;
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		dfs(b,x);
	}
}
int ss[SZ],sn=0;
int oo[23333333],on=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",col+i), col[i]=col[i]<0;
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d%d",&a,&b);
		adde(a,b);
	}
	dfs(1,0);
	int t=0;
	for(int i=2;i<=n;i++)
	{
		if(col[i])
		{
			sn=0; int cur=i;
			while(cur!=1) ss[++sn]=cur, cur=fa[cur];
			if(t&1);else oo[++on]=1;
			for(int i=sn;i>=1;i--) oo[++on]=ss[i];
			for(int i=2;i<=sn;i++) oo[++on]=ss[i];
			if(t&1);else oo[++on]=1;
			++t;
		}
	}
	if(col[1])
	{
		if(oo[on]==1) --on;
		else oo[++on]=1;
	}
	for(int i=1;i<=on;i++) printf("%d ",oo[i]);
	if(!t) puts("1");
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n,col[SZ];
Edg
int fa[SZ];
void dfs(int x,int f)
{
	fa[x]=f;
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		dfs(b,x);
	}
}
int ss[SZ],sn=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",col+i), col[i]=col[i]<0;
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d%d",&a,&b);
		adde(a,b);
	}
	dfs(1,0);
	int t=0;
	for(int i=1;i<=n;i++)
	{
		if(col[i])
		{
			sn=0; int cur=i;
			while(cur!=1) ss[++sn]=cur, cur=fa[cur];
			if(t&1);else printf("1 ");
			for(int i=sn;i>=1;i--) printf("%d ",ss[i]);
			for(int i=2;i<=sn;i++) printf("%d ",ss[i]);
			if(t&1);else printf("1 ");
			++t;
		}
	}
	if(!t) puts("1");
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n,col[SZ];
Edg
int oo[SZ],on=0;
void dfs(int x,int f)
{
	oo[++on]=x; col[x]^=1;
	bool down=0;
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		dfs(b,x); oo[++on]=x, col[x]^=1;
	}
	if(col[x]&&x!=1)
	{
	oo[++on]=f;
	oo[++on]=x; col[x]^=1;
	oo[++on]=f;
	}
}
int main()
{
	scanf("%d",&n);
	int cc=0,p;
	for(int i=1;i<=n;i++)
	scanf("%d",col+i), col[i]=col[i]<0, cc+=col[i];
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d%d",&a,&b);
		if(a>b) swap(a,b);
		if(a==1) p=b;
		adde(a,b);
	}
	if(cc==1&&col[1])
	{
		printf("1 %d 1 %d\n",p,p);
		return 0;
	}
	dfs(1,0);
	if(!col[1])
	{
		if(oo[on]==1) --on;
		else oo[++on]=1;
	}
	for(int i=1;i<=on;i++) printf("%d ",oo[i]);
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n,col[SZ];
Edg
int oo[23333333],on=0;
void dfs(int x,int f)
{
	oo[++on]=x; col[x]^=1;
	bool down=0;
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		dfs(b,x); oo[++on]=x, col[x]^=1;
	}
	if(col[x]&&x!=1)
	{
	oo[++on]=f;
	oo[++on]=x; col[x]^=1;
	oo[++on]=f;
	}
}
int main()
{
	scanf("%d",&n);
	int cc=0,p;
	for(int i=1;i<=n;i++)
	scanf("%d",col+i), col[i]=col[i]<0, cc+=col[i];
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d%d",&a,&b);
		if(a>b) swap(a,b);
		if(a==1) p=b;
		adde(a,b);
	}
	if(cc==1&&col[1])
	{
		printf("1 %d 1 %d\n",p,p);
		return 0;
	}
	col[1]^=1;
	dfs(1,0);
	if(col[1])
	{
		if(oo[on]==1) --on;
		else oo[++on]=1;
	}
	for(int i=1;i<=on;i++) printf("%d ",oo[i]);
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n,col[SZ];
Edg
int fa[SZ];
void dfs(int x,int f)
{
	fa[x]=f;
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		dfs(b,x);
	}
}
int ss[SZ],sn=0;
int oo[233333330],on=0;
map<int,bool> rp[2333];
int pm[SZ];
int main()
{
	scanf("%d",&n);
	int cc=0;
	//for(int i=1;i<=n;i++) col[i]=0;
	//col[1]=1;
	//for(int i=1;i<=n;i++) pm[i]=i;
	//random_shuffle(pm+1,pm+1+n);
	for(int i=1;i<=n;i++)
	scanf("%d",col+i), col[i]=col[i]<0;
	for(int i=1;i<=n;i++) cc+=col[i];
	int p=0;
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d%d",&a,&b);
		//a=rand()%i+1; b=i+1;
		if(a>b) swap(a,b);
		if(a==1) p=b;
		//a=pm[a]; b=pm[b];
		//rp[a][b]=rp[b][a]=1;
		adde(a,b);
	}
	if(cc==1&&col[1])
	{
		printf("1 %d 1 %d\n",p,p);
		return 0;
	}
	dfs(1,0);
	int t=0;
	for(int i=2;i<=n;i++)
	{
		if(col[i])
		{
			sn=0; int cur=i;
			while(cur!=1) ss[++sn]=cur, cur=fa[cur];
			if(t&1);else oo[++on]=1;
			for(int i=sn;i>=1;i--) oo[++on]=ss[i];
			for(int i=2;i<=sn;i++) oo[++on]=ss[i];
			if(t&1);else oo[++on]=1;
			++t;
		}
	}
	if(!col[1])
	{
		if(oo[on]==1) --on;
		else oo[++on]=1;
	}
	for(int i=1;i<=on;i++) printf("%d ",oo[i]);
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n,col[SZ];
Edg
int oo[23333333],on=0;
void dfs(int x,int f)
{
	oo[++on]=x; col[x]^=1;
	bool down=0;
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		dfs(b,x); oo[++on]=x, col[x]^=1;
	}
	if(col[x]&&x!=1)
	{
	oo[++on]=f, col[f]^=1;
	oo[++on]=x; col[x]^=1;
	}
}
//bool colp[SZ];
//map<int,int> rs[2333];
int main()
{
	scanf("%d",&n);
	int cc=0,p;
	for(int i=1;i<=n;i++)
	scanf("%d",col+i), col[i]=col[i]<0, cc+=col[i];
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d%d",&a,&b);
		//a=rand()%i+1, b=i+1;
		//cout<<a<<","<<b<<"\n";
		if(a>b) swap(a,b);
		if(a==1) p=b;
		//rs[a][b]=rs[b][a]=1;
		adde(a,b);
	}
	if(cc==1&&col[1])
	{
		printf("1 %d 1 %d\n",p,p);
		return 0;
	}
	col[1]^=1;
	dfs(1,0);
	if(col[1])
	{
		if(oo[on]==1) --on;
		else oo[++on]=1;
	}
	/*
	for(int i=2;i<=on;i++) if(rs[oo[i]][oo[i-1]]!=1) cout<<"WA\n";
	for(int i=2;i<=on;i++) colp[oo[i]]^=1;
	for(int i=1;i<=n;i++) if(colp[i]) cout<<"WA\n";*/
	for(int i=1;i<=on;i++) printf("%d ",oo[i]);
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n,col[SZ];
Edg
int fa[SZ];
void dfs(int x,int f)
{
	fa[x]=f;
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		dfs(b,x);
	}
}
int ss[SZ],sn=0;
int oo[23333333],on=0;
map<int,bool> rp[2333];
int pm[SZ];
int main()
{
	scanf("%d",&n);
	int cc=0;
	//for(int i=1;i<=n;i++) col[i]=0;
	//col[1]=1;
	//for(int i=1;i<=n;i++) pm[i]=i;
	//random_shuffle(pm+1,pm+1+n);
	for(int i=1;i<=n;i++)
	scanf("%d",col+i), col[i]=col[i]<0;
	for(int i=1;i<=n;i++) cc+=col[i];
	int p=0;
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d%d",&a,&b);
		//a=rand()%i+1; b=i+1;
		if(a>b) swap(a,b);
		if(a==1) p=b;
		//a=pm[a]; b=pm[b];
		//rp[a][b]=rp[b][a]=1;
		adde(a,b);
	}
	if(cc==1&&col[1])
	{
		printf("1 %d 1 %d\n",p,p);
		return 0;
	}
	dfs(1,0);
	int t=0;
	for(int i=2;i<=n;i++)
	{
		if(col[i])
		{
			sn=0; int cur=i;
			while(cur!=1) ss[++sn]=cur, cur=fa[cur];
			if(t&1);else oo[++on]=1;
			for(int i=sn;i>=1;i--) oo[++on]=ss[i];
			for(int i=2;i<=sn;i++) oo[++on]=ss[i];
			if(t&1);else oo[++on]=1;
			++t;
		}
	}
	if(!col[1])
	{
		if(oo[on]==1) --on;
		else oo[++on]=1;
	}
	for(int i=1;i<=on;i++) printf("%d ",oo[i]);
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n,col[SZ];
Edg
int fa[SZ];
void dfs(int x,int f)
{
	fa[x]=f;
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		dfs(b,x);
	}
}
int ss[SZ],sn=0;
int oo[23333333],on=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",col+i), col[i]=col[i]<0;
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d%d",&a,&b);
		adde(a,b);
	}
	dfs(1,0);
	int t=0;
	for(int i=2;i<=n;i++)
	{
		if(col[i])
		{
			sn=0; int cur=i;
			while(cur!=1) ss[++sn]=cur, cur=fa[cur];
			if(t&1);else oo[++on]=1;
			for(int i=sn;i>=1;i--) oo[++on]=ss[i];
			for(int i=2;i<=sn;i++) oo[++on]=ss[i];
			if(t&1);else oo[++on]=1;
			++t;
		}
	}
	if(!col[1])
	{
		if(oo[on]==1) --on;
		else oo[++on]=1;
	}
	for(int i=1;i<=on;i++) printf("%d ",oo[i]);
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n,col[SZ];
Edg
int fa[SZ];
void dfs(int x,int f)
{
	fa[x]=f;
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		dfs(b,x);
	}
}
int ss[SZ],sn=0;
int oo[23333333],on=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",col+i), col[i]=col[i]<0;
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d%d",&a,&b);
		adde(a,b);
	}
	dfs(1,0);
	int t=0;
	for(int i=2;i<=n;i++)
	{
		if(col[i])
		{
			sn=0; int cur=i;
			while(cur!=1) ss[++sn]=cur, cur=fa[cur];
			if(t&1);else oo[++on]=1;
			for(int i=sn;i>=1;i--) oo[++on]=ss[i];
			for(int i=2;i<=sn;i++) oo[++on]=ss[i];
			if(t&1);else oo[++on]=1;
			++t;
		}
	}
	if(!col[1])
	{
		if(oo[on]==1) --on;
		else oo[++on]=1;
	}
	for(int i=1;i<=on;i++) printf("%d ",oo[i]);
	if(!t) puts("1");
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n,col[SZ];
Edg
int fa[SZ];
void dfs(int x,int f)
{
	fa[x]=f;
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		dfs(b,x);
	}
}
int ss[SZ],sn=0;
int oo[53333333],on=0;
map<int,bool> rp[2333];
int pm[SZ];
int main()
{
	scanf("%d",&n);
	int cc=0;
	//for(int i=1;i<=n;i++) col[i]=0;
	//col[1]=1;
	//for(int i=1;i<=n;i++) pm[i]=i;
	//random_shuffle(pm+1,pm+1+n);
	for(int i=1;i<=n;i++)
	scanf("%d",col+i), col[i]=col[i]<0;
	for(int i=1;i<=n;i++) cc+=col[i];
	int p=0;
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d%d",&a,&b);
		//a=rand()%i+1; b=i+1;
		if(a>b) swap(a,b);
		if(a==1) p=b;
		//a=pm[a]; b=pm[b];
		//rp[a][b]=rp[b][a]=1;
		adde(a,b);
	}
	if(cc==1&&col[1])
	{
		printf("1 %d 1 %d\n",p,p);
		return 0;
	}
	dfs(1,0);
	int t=0;
	for(int i=2;i<=n;i++)
	{
		if(col[i])
		{
			sn=0; int cur=i;
			while(cur!=1) ss[++sn]=cur, cur=fa[cur];
			if(t&1);else oo[++on]=1;
			for(int i=sn;i>=1;i--) oo[++on]=ss[i];
			for(int i=2;i<=sn;i++) oo[++on]=ss[i];
			if(t&1);else oo[++on]=1;
			++t;
		}
	}
	if(!col[1])
	{
		if(oo[on]==1) --on;
		else oo[++on]=1;
	}
	for(int i=1;i<=on;i++) printf("%d ",oo[i]);
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#ifdef LOCAL
#define TIMER cerr<<clock()<<"ms\n"
#else
#define TIMER
#endif
#define SZ 666666
int n,col[SZ];
Edg
int fa[SZ];
void dfs(int x,int f)
{
	fa[x]=f;
	for es(x,e)
	{
		int b=vb[e]; if(b==f) continue;
		dfs(b,x);
	}
}
int ss[SZ],sn=0;
vector<int> oo;
map<int,bool> rp[2333];
int pm[SZ];
int main()
{
	scanf("%d",&n);
	int cc=0;
	//for(int i=1;i<=n;i++) col[i]=0;
	//col[1]=1;
	//for(int i=1;i<=n;i++) pm[i]=i;
	//random_shuffle(pm+1,pm+1+n);
	for(int i=1;i<=n;i++)
	scanf("%d",col+i), col[i]=col[i]<0;
	for(int i=1;i<=n;i++) cc+=col[i];
	int p=0;
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d%d",&a,&b);
		//a=rand()%i+1; b=i+1;
		if(a>b) swap(a,b);
		if(a==1) p=b;
		//a=pm[a]; b=pm[b];
		//rp[a][b]=rp[b][a]=1;
		adde(a,b);
	}
	if(cc==1&&col[1])
	{
		printf("1 %d 1 %d\n",p,p);
		return 0;
	}
	dfs(1,0);
	int t=0;
	for(int i=2;i<=n;i++)
	{
		if(col[i])
		{
			sn=0; int cur=i;
			while(cur!=1) ss[++sn]=cur, cur=fa[cur];
			if(t&1);else oo.push_back(1);
			for(int i=sn;i>=1;i--) oo.push_back(ss[i]);
			for(int i=2;i<=sn;i++) oo.push_back(ss[i]);
			if(t&1);else oo.push_back(1);
			++t;
		}
	}
	if(!col[1])
	{
		if(oo[on]==1) oo.pop_back(1);
		else oo.push_back(1);
	}
	for(int i=0;i<oo.size();i++) printf("%d ",oo[i]);
}


#include <bits/stdc++.h>
#define FOR(i, j, k) for (int i = j; i <= k; i ++)
#define FORD(i, j, k) for (int i = j; i >= k; i --)
#define mn 200005
#define maxC 10007
#define pb push_back
#define F first
#define S second
#define mp make_pair

using namespace std;
int n, co[mn], num[mn], chi[mn];
vector<int> g[mn], ans;

void dfs1(int u, int p = 0)
{
    num[u] = co[u];
    FOR(i, 0, int(g[u].size()) - 1)
    {
        int v = g[u][i];
        if (v == p)
            continue;
        dfs1(v, u);
        num[u] += num[v];
        chi[u] += co[v];
    }
}

void dfs2(int u, int p = 0)
{
    ans.pb(u);
    FOR(i, 0, int(g[u].size()) - 1)
    {
        int v = g[u][i];
        if (v == p)
            continue;
        if (num[v])
        {
            co[v] ^= 1;
            dfs2(v, u);
            ans.pb(u);
            if (co[v] == 0)
                co[u] ^= 1;
            else
            {
                ans.pb(v);
                ans.pb(u);
            }
        }
    }
}

void setup()
{
    cin >> n;
    FOR(i, 1, n)
    {
        cin >> co[i];
        co[i] = (co[i] == -1);
    }
    FOR(i, 2, n)
    {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs1(1);
    dfs2(1);
    FOR(i, 0, int(ans.size()) - 1)
        cout << ans[i] << ' ';
}

void xuly()
{

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    setup ();
    xuly ();
    return 0;
}


#include <bits/stdc++.h>
#define FOR(i, j, k) for (int i = j; i <= k; i ++)
#define FORD(i, j, k) for (int i = j; i >= k; i --)
#define mn 200005
#define maxC 10007
#define pb push_back
#define F first
#define S second
#define mp make_pair

using namespace std;
int n, co[mn], num[mn], chi[mn], all;
vector<int> g[mn], ans;

void dfs1(int u, int p = 0)
{
    num[u] = co[u];
    FOR(i, 0, int(g[u].size()) - 1)
    {
        int v = g[u][i];
        if (v == p)
            continue;
        dfs1(v, u);
        num[u] += num[v];
        chi[u] += co[v];
    }
}

void switc(int u)
{
    all -= co[u];
    co[u] ^= 1;
    all += co[u];
}

void print()
{
    FOR(i, 0, int(ans.size()) - 1)
        cout << ans[i] << ' ';
    exit(0);
}

void dfs2(int u, int p = 0)
{
    ans.pb(u);
    FOR(i, 0, int(g[u].size()) - 1)
    {
        int v = g[u][i];
        if (v == p)
            continue;
        if (num[v])
        {
            switc(v);
            dfs2(v, u);
            ans.pb(u);
            if (co[v] == 0)
            {
                switc(u);
                if (all == 0)
                    print();
            }
            else
            {
                switc(v);
                ans.pb(v);
                if (all == 0)
                    print();
                ans.pb(u);
                if (all == 0)
                    print();
            }
        }
    }
}

void setup()
{
    cin >> n;
    FOR(i, 1, n)
    {
        cin >> co[i];
        co[i] = (co[i] == -1);
    }
    FOR(i, 2, n)
    {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs1(1);
    all = num[1];
    dfs2(1);
}

void xuly()
{

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    setup ();
    xuly ();
    return 0;
}


#include <bits/stdc++.h>
#define FOR(i, j, k) for (int i = j; i <= k; i ++)
#define FORD(i, j, k) for (int i = j; i >= k; i --)
#define mn 200005
#define maxC 10007
#define pb push_back
#define F first
#define S second
#define mp make_pair

using namespace std;
int n, co[mn], num[mn], chi[mn], all;
vector<int> g[mn], ans;

void dfs1(int u, int p = 0)
{
    num[u] = co[u];
    FOR(i, 0, int(g[u].size()) - 1)
    {
        int v = g[u][i];
        if (v == p)
            continue;
        dfs1(v, u);
        num[u] += num[v];
        chi[u] += co[v];
    }
}

void switc(int u)
{
    all -= co[u];
    co[u] ^= 1;
    all += co[u];
}

void print()
{
    FOR(i, 0, int(ans.size()) - 1)
        cout << ans[i] << ' ';
    exit(0);
}

void dfs2(int u, int p = 0)
{
    ans.pb(u);
    if (all == 0)
        print();
    FOR(i, 0, int(g[u].size()) - 1)
    {
        int v = g[u][i];
        if (v == p)
            continue;
        if (num[v])
        {
            switc(v);
            dfs2(v, u);
            ans.pb(u);
            if (co[v] == 0)
            {
                switc(u);
                if (all == 0)
                    print();
            }
            else
            {
                switc(v);
                ans.pb(v);
                if (all == 0)
                    print();
                ans.pb(u);
                if (all == 0)
                    print();
            }
        }
    }
}

void setup()
{
    cin >> n;
    FOR(i, 1, n)
    {
        cin >> co[i];
        co[i] = (co[i] == -1);
    }
    FOR(i, 2, n)
    {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs1(1);
    all = num[1];
    dfs2(1);
}

void xuly()
{

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    setup ();
    xuly ();
    return 0;
}


#include <bits/stdc++.h>
#define FOR(i, j, k) for (int i = j; i <= k; i ++)
#define FORD(i, j, k) for (int i = j; i >= k; i --)
#define mn 200005
#define maxC 10007
#define pb push_back
#define F first
#define S second
#define mp make_pair

using namespace std;
int n, co[mn], num[mn], all;
vector<int> g[mn], ans;

void dfs1(int u, int p = 0)
{
    num[u] = co[u];
    FOR(i, 0, int(g[u].size()) - 1)
    {
        int v = g[u][i];
        if (v == p)
            continue;
        dfs1(v, u);
        num[u] += num[v];
    }
}

void switc(int u)
{
    ans.pb(u);
    all -= co[u];
    co[u] ^= 1;
    all += co[u];
    if (all == 0)
    {
        FOR(i, 0, int(ans.size()) - 1)
            cout << ans[i] << ' ';
        exit(0);
    }
}

void dfs2(int u, int p = 0)
{
    switc(u);
    FOR(i, 0, int(g[u].size()) - 1)
    {
        int v = g[u][i];
        if (v == p)
            continue;
        if (num[v])
        {
            dfs2(v, u);
            switc(u);
            if (co[v])
            {
                switc(v);
                switc(u);
            }
        }
    }
}

void setup()
{
    cin >> n;
    FOR(i, 1, n)
    {
        cin >> co[i];
        co[i] = (co[i] == -1);
    }
    co[1] ^= 1;
    FOR(i, 2, n)
    {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs1(1);
    all = num[1];
    dfs2(1);
}

void xuly()
{

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    setup ();
    xuly ();
    return 0;
}


#include <bits/stdc++.h>
#define FOR(i, j, k) for (int i = j; i <= k; i ++)
#define FORD(i, j, k) for (int i = j; i >= k; i --)
#define mn 200005
#define maxC 10007
#define pb push_back
#define F first
#define S second
#define mp make_pair

using namespace std;
int n, co[mn], num[mn], chi[mn], all;
vector<int> g[mn], ans;

void dfs1(int u, int p = 0)
{
    num[u] = co[u];
    FOR(i, 0, int(g[u].size()) - 1)
    {
        int v = g[u][i];
        if (v == p)
            continue;
        dfs1(v, u);
        num[u] += num[v];
        chi[u] += co[v];
    }
}

void switc(int u)
{
    all -= co[u];
    co[u] ^= 1;
    all += co[u];
}

void print()
{
    FOR(i, 0, int(ans.size()) - 1)
        cout << ans[i] << ' ';
    exit(0);
}

void dfs2(int u, int p = 0)
{
    ans.pb(u);
    FOR(i, 0, int(g[u].size()) - 1)
    {
        int v = g[u][i];
        if (v == p)
            continue;
        if (num[v])
        {
            switc(v);
            dfs2(v, u);
            ans.pb(u);
            if (co[v] == 0)
            {
                switc(u);
                if (all == 0)
                    print();
            }
            else
            {
                switc(v);
                ans.pb(v);
                if (all == 0)
                    print();
                ans.pb(u);
            }
        }
    }
}

void setup()
{
    cin >> n;
    FOR(i, 1, n)
    {
        cin >> co[i];
        co[i] = (co[i] == -1);
    }
    FOR(i, 2, n)
    {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs1(1);
    all = num[1];
    dfs2(1);
}

void xuly()
{

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    setup ();
    xuly ();
    return 0;
}


#include <bits/stdc++.h>
#define FOR(i, j, k) for (int i = j; i <= k; i ++)
#define FORD(i, j, k) for (int i = j; i >= k; i --)
#define mn 200005
#define maxC 10007
#define pb push_back
#define F first
#define S second
#define mp make_pair

using namespace std;
int n, co[mn], num[mn], all;
vector<int> g[mn], ans;

void dfs1(int u, int p = 0)
{
    num[u] = co[u];
    FOR(i, 0, int(g[u].size()) - 1)
    {
        int v = g[u][i];
        if (v == p)
            continue;
        dfs1(v, u);
        num[u] += num[v];
    }
}

void switc(int u)
{
    ans.pb(u);
    all -= co[u];
    co[u] ^= 1;
    all += co[u];
    if (all == 0)
    {
        FOR(i, 0, int(ans.size()) - 1)
            cout << ans[i] << ' ';
        exit(0);
    }
}

void dfs2(int u, int p = 0)
{
    switc(u);
    FOR(i, 0, int(g[u].size()) - 1)
    {
        int v = g[u][i];
        if (v == p)
            continue;
        if (num[v])
        {
            dfs2(v, u);
            switc(u);
            if (co[v])
            {
                switc(v);
                switc(u);
            }
        }
    }
}

void setup()
{
    cin >> n;
    FOR(i, 1, n)
    {
        cin >> co[i];
        co[i] = (co[i] == -1);
    }
    co[1] ^= 1;
    FOR(i, 2, n)
    {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs1(1);
    all = num[1];
    dfs2(1);
    switc(g[1][0]);
    switc(1);
    switc(g[1][0]);
}

void xuly()
{

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    setup ();
    xuly ();
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
struct node
{
	int y,next;
}a[400010];
int first[200010],len;
int A[200010];
bool v[200010],o[200010];
bool f[200010],g[200010];
void ins(int x,int y)
{
	a[++len].y=y;
	a[len].next=first[x];
	first[x]=len;
}
void dfs(int x,int fa)
{
	int k,y,ok1=1;
	v[x]=A[x];
	for(k=first[x];k;k=a[k].next)
	{
	  y=a[k].y;
	  if(y==fa)continue;
	  dfs(y,x);
	  v[x]|=v[y];
	}
	if(v[x])
	{
	  int ok=1,s=0;
	  for(k=first[x];k;k=a[k].next)
	  {
		y=a[k].y;
		if(y==fa)continue;
		if(v[y])
		{
		  if(!f[y])ok=0;
		  s++;
		}
	  }if(x==4)printf("ok %d %d\n",ok,s);
	  o[x]=ok;
	  if(ok&&(A[x]+1+s)%2==0)f[x]=1;
	  if(f[x])g[x]=1;
	  else if((A[x]+1+s)%2==1)
	  {
		s=0;int ss=0;
	    for(k=first[x];k;k=a[k].next)
	    {
		  y=a[k].y;
		  if(y==fa)continue;
		  if(ok)
		  {
			if(g[y])s++;
		  }
		  else
		  {
			if(!f[x])ss++;
			if(!f[x]&&g[x])s++;
		  }
	    }
		if(ok)
		{
		  if(s)g[x]=1;
		}
	    else if(ss==1&&s==1)g[x]=1;
	  }
	}
}
void DFS(int x,int fa,int K)
{
	int k,y;
    if(f[x])
	{
	  printf("%d ",x);
	  for(k=first[x];k;k=a[k].next)
	  {
		y=a[k].y;
		if(y==fa)continue;
		if(v[y])
		{
		  DFS(y,x,0);
	      printf("%d ",x);
	    }
	  }
	}
	else
	{
	  printf("%d ",x);
	  int xx=0;
	  for(k=first[x];k;k=a[k].next)
	  {
		y=a[k].y;
		if(y==fa)continue;
		if(v[y])
		{
		  if(o[x])
		  {
			if(f[y]&&!xx)xx=y;
			else{DFS(y,x,0);printf("%d ",x);}
		  }
		  else
		  {
			if(!f[y])xx=y;
			else{DFS(y,x,0);printf("%d ",x);}
		  }
	    }
	  }
	  DFS(xx,x,1);
	}
}
int main()
{
	int n,i,j,x,y;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
	  scanf("%d",&x);
	  if(x==1)A[i]=0;
	  else A[i]=1;
	}
	A[1]^=1;
	for(i=1;i<n;i++)
	{
	  scanf("%d%d",&x,&y);
	  ins(x,y);ins(y,x);
	}
	dfs(1,0);
	for(i=1;i<=n;i++)printf("%d:%d %d\n",i,f[i],g[i]);
	DFS(1,0,1);
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
struct node
{
	int y,next;
}a[400010];
int first[200010],len;
int A[200010];
void ins(int x,int y)
{
	a[++len].y=y;
	a[len].next=first[x];
	first[x]=len;
}
void dfs(int x,int fa)
{
    int k,y;
	A[x]^=1;
	printf("%d ",x);
	for(k=first[x];k;k=a[k].next)
	{
	  y=a[k].y;
	  if(y==fa)continue;
	  dfs(y,x);
	  A[x]^=1;
	  printf("%d ",x);
	}
	if(A[x]&&fa){printf("%d %d ",fa,x);A[fa]^=1;}
}
int main()
{
	int n,i,j,x,y;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
	  scanf("%d",&x);
	  if(x==1)A[i]=0;
	  else A[i]=1;
	}
	for(i=1;i<n;i++)
	{
	  scanf("%d%d",&x,&y);
	  ins(x,y);ins(y,x);
	}
	dfs(1,0);
	if(A[1])printf("%d %d %d ",a[first[1]].y,1,a[first[1]].y);
	printf("\n");
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
struct node
{
	int y,next;
}a[400010];
int first[200010],len;
int A[200010];
void ins(int x,int y)
{
	a[++len].y=y;
	a[len].next=first[x];
	first[x]=len;
}
void dfs(int x,int fa)
{
    int k,y;
	A[x]^=1;
	printf("%d ",x);
	for(k=first[x];k;k=a[k].next)
	{
	  y=a[k].y;
	  if(y==fa)continue;
	  dfs(y,x);
	  A[x]^=1;
	  printf("%d ",x);
	}
	if(A[x]&&fa){printf("%d %d ",fa,x);A[fa]^=1;}
}
int main()
{
	int n,i,j,x,y;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
	  scanf("%d",&x);
	  if(x==1)A[i]=0;
	  else A[i]=1;
	}
	A[1]^=1;
	for(i=1;i<n;i++)
	{
	  scanf("%d%d",&x,&y);
	  ins(x,y);ins(y,x);
	}
	dfs(1,0);
	if(A[1])printf("%d %d %d ",a[first[1]].y,1,a[first[1]].y);
	printf("\n");
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
struct node
{
	int y,next;
}a[400010];
int first[200010],len;
int A[200010];
bool v[200010],o[200010];
bool f[200010],g[200010];
void ins(int x,int y)
{
	a[++len].y=y;
	a[len].next=first[x];
	first[x]=len;
}
void dfs(int x,int fa)
{
	int k,y,ok1=1;
	v[x]=A[x];
	for(k=first[x];k;k=a[k].next)
	{
	  y=a[k].y;
	  if(y==fa)continue;
	  dfs(y,x);
	  v[x]|=v[y];
	}
	if(v[x])
	{
	  int ok=1,s=0;
	  for(k=first[x];k;k=a[k].next)
	  {
		y=a[k].y;
		if(y==fa)continue;
		if(v[y])
		{
		  if(!f[y])ok=0;
		  s++;
		}
	  }
	  o[x]=ok;
	  if(ok&&(A[x]+1+s)%2==0)f[x]=1;
	  if(f[x])g[x]=1;
	  else if((A[x]+1+s)%2==1)
	  {
		s=0;int ss=0;
	    for(k=first[x];k;k=a[k].next)
	    {
		  y=a[k].y;
		  if(y==fa)continue;
		  if(ok)
		  {
			if(g[y])s++;
		  }
		  else
		  {
			if(!f[x])ss++;
			if(!f[x]&&g[x])s++;
		  }
	    }
		if(ok)
		{
		  if(s)g[x]=1;
		}
	    else if(ss==1&&s==1)g[x]=1;
	  }
	}
}
void DFS(int x,int fa,int K)
{
	int k,y;
    if(f[x])
	{
	  printf("%d ",x);
	  for(k=first[x];k;k=a[k].next)
	  {
		y=a[k].y;
		if(y==fa)continue;
		if(v[y])
		{
		  DFS(y,x,0);
	      printf("%d ",x);
	    }
	  }
	}
	else
	{
	  printf("%d ",x);
	  int xx=0;
	  for(k=first[x];k;k=a[k].next)
	  {
		y=a[k].y;
		if(y==fa)continue;
		if(v[y])
		{
		  if(o[x])
		  {
			if(f[y]&&!xx)xx=y;
			else{DFS(y,x,0);printf("%d ",x);}
		  }
		  else
		  {
			if(!f[y])xx=y;
			else{DFS(y,x,0);printf("%d ",x);}
		  }
	    }
	  }
	  DFS(xx,x,1);
	}
}
int main()
{
	int n,i,j,x,y;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
	  scanf("%d",&x);
	  if(x==1)A[i]=0;
	  else A[i]=1;
	}
	A[1]^=1;
	for(i=1;i<n;i++)
	{
	  scanf("%d%d",&x,&y);
	  ins(x,y);ins(y,x);
	}
	dfs(1,0);
	DFS(1,0,1);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<vector>

using namespace std;
int a[100006];
vector<int> vec[100006];

void put(int kk)
{
	a[kk]=-a[kk];
	cout <<" "<<kk+1;
}

void dfs(int v,int k)
{
	for(int i=0;i<vec[v].size();i++)
	{
		int u=vec[v][i];
		if(u==k)
			continue;
		put(u);

		dfs(u,v);
		put(v);
		if(a[u]==-1)
		{
			put(u);
			put(v);
		}
	}
	if(v==0&&a[v]==-1)
	{
		int u=vec[v][0];
		put(u);
		put(v);
		put(u);
	}

}

int main()
{
	int n;
	cin >>n;

	for(int i=0;i<n;i++)
	{
		cin >>a[i];
	}
	int x,y;
	for(int i=0;i<n-1;i++)
	{
		cin >>x>>y;
		x--;
		y--;
		vec[x].push_back(y);
		vec[y].push_back(x);
	}
	cout <<1;

	dfs(0,-1);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 200005;

int a[maxn], cha[maxn], vis[maxn];
int n, cnt;
vector <int> ke[maxn];

void nhap()
{
	scanf("%d", &n);
	cnt = 0;
	for(int i=1; i<=n; i++)
	{
		scanf("%d", &a[i]);
		cnt += (a[i] == 1);
	}
	for(int i=1; i<n; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		ke[u].push_back(v);
		ke[v].push_back(u);
	}
}

void dfs(int u)
{
	printf("%d ", u);
	a[u] = - a[u];
	for(int j=0; j<ke[u].size(); j++)
	{
		int v = ke[u][j];
		if (!vis[v])
		{
			cha[v] = u;
			vis[v] = 1;
			dfs(v);
			if (u != 1 || j != (int)(ke[u].size()) - 1)
			{
				printf("%d ", u);
				a[u] = - a[u];
			} else
			{
				if (a[u] == -1)
				{
					printf("%d ", u);
					a[u] = - a[u];
				}
			}
		}
	}
	if (a[u] == -1)
	{
		printf("%d ", cha[u]);
		a[cha[u]] = - a[cha[u]];
		printf("%d ", u);
		a[u] = - a[u];
	}
}

int main()
{
	//freopen("test.inp", "r", stdin);
	nhap();
	if (cnt == n)
	{
		printf("1\n");
		return 0;
	}
	a[1] = -a[1];
	memset(vis,0,sizeof(vis));
	vis[1] = 1;
	dfs(1);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cmath>
#include <stack>
#include <string>
#define mod 1000000009
#define eps 1e-5
#define pi acos(-1)
#define N 200010
using namespace std;
typedef pair<int,int>pa;
typedef __int64 LL;
int c[N];
int n;
struct edge{
	int b,nt;
}e[N*2];

int p[N],nn;
void aedge(int x,int y){
	nn++;e[nn].b=y;e[nn].nt=p[x];p[x]=nn;
}

void anode(int x,int y){
	aedge(x,y);aedge(y,x);
}
int flag[N],deep[N];
void dfs(int x){
	if(c[x]==-1)flag[x]=1;
	for(int i=p[x];i ;i=e[i].nt){
		int t=e[i].b;
		if(!deep[t]){
			deep[t]=deep[x]+1;
			dfs(t);
			if(flag[t])flag[x]=1;
		}
	}
}

void solve(int x){
	printf("%d ",x);
	if(x!=1)c[x]*=-1;
	for(int i=p[x];i;i=e[i].nt){
		int t=e[i].b;
		if(flag[t]&&deep[t]>deep[x]||x==1){
			solve(t);
			printf("%d ",x);c[x]*=-1;
			if(c[t]<0){
				printf("%d %d ",t,x);
				c[t]*=-1;c[x]*=-1;
			}
		}
	}
	if(x==1&&c[x]==-1){
		int t=e[p[1]].b;
		printf("%d %d %d",t,x,t);
		c[x]*=-1;
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&c[i]);
	for(int i=1;i<n;i++){
		int aa,bb;
		scanf("%d%d",&aa,&bb);
		anode(aa,bb);
	}deep[1]=1;
	dfs(1);
	solve(1);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cmath>
#include <stack>
#include <string>
#define mod 1000000009
#define eps 1e-5
#define pi acos(-1)
#define N 200010
using namespace std;
typedef pair<int,int>pa;
typedef __int64 LL;
int c[N];
int n;
struct edge{
	int b,nt;
}e[N*2];

int p[N],nn;
void aedge(int x,int y){
	nn++;e[nn].b=y;e[nn].nt=p[x];p[x]=nn;
}

void anode(int x,int y){
	aedge(x,y);aedge(y,x);
}
int flag[N],deep[N];
void dfs(int x){
	if(c[x]==-1)flag[x]=1;
	for(int i=p[x];i ;i=e[i].nt){
		int t=e[i].b;
		if(!deep[t]){
			deep[t]=deep[x]+1;
			dfs(t);
			if(flag[t])flag[x]=1;
		}
	}
}

void solve(int x){
	printf("%d ",x);c[x]*=-1;
	for(int i=p[x];i;i=e[i].nt){
		int t=e[i].b;
		if(flag[t]&&deep[t]>deep[x]||x==1){
			solve(t);
			printf("%d ",x);c[x]*=-1;
			if(c[t]<0){
				printf("%d %d ",t,x);
				c[t]*=-1;c[x]*=-1;
			}
		}
	}
	if(x==1&&c[x]==-1){
		int t=e[p[1]].b;
		printf("%d %d %d",t,x,t);
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&c[i]);
	for(int i=1;i<n;i++){
		int aa,bb;
		scanf("%d%d",&aa,&bb);
		anode(aa,bb);
	}deep[1]=1;
	dfs(1);
	solve(1);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cmath>
#include <stack>
#include <string>
#define mod 1000000009
#define eps 1e-5
#define pi acos(-1)
#define N 200010
using namespace std;
typedef pair<int,int>pa;
typedef __int64 LL;
int c[N];
int n;
struct edge{
	int b,nt;
}e[N*2];

int p[N],nn;
void aedge(int x,int y){
	nn++;e[nn].b=y;e[nn].nt=p[x];p[x]=nn;
}

void anode(int x,int y){
	aedge(x,y);aedge(y,x);
}
int flag[N],deep[N];
void dfs(int x){
	if(c[x]==-1)flag[x]=1;
	for(int i=p[x];i ;i=e[i].nt){
		int t=e[i].b;
		if(!deep[t]){
			deep[t]=deep[x]+1;
			dfs(t);
			if(flag[t])flag[x]=1;
		}
	}
}

void solve(int x){
	printf("%d ",x);c[x]*=-1;
	for(int i=p[x];i;i=e[i].nt){
		int t=e[i].b;
		if(flag[t]&&deep[t]>deep[x]){
			solve(t);
			printf("%d ",x);c[x]*=-1;
			if(c[t]<0){
				printf("%d %d ",t,x);
			}
		}
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&c[i]);
	for(int i=1;i<n;i++){
		int aa,bb;
		scanf("%d%d",&aa,&bb);
		anode(aa,bb);
	}deep[1]=1;
	dfs(1);
	solve(1);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cmath>
#include <stack>
#include <string>
#define mod 1000000009
#define eps 1e-5
#define pi acos(-1)
#define N 200010
using namespace std;
typedef pair<int,int>pa;
typedef __int64 LL;
int c[N];
int n;
struct edge{
	int b,nt;
}e[N*2];

int p[N],nn;
void aedge(int x,int y){
	nn++;e[nn].b=y;e[nn].nt=p[x];p[x]=nn;
}

void anode(int x,int y){
	aedge(x,y);aedge(y,x);
}
int flag[N],deep[N];
void dfs(int x){
	if(c[x]==-1)flag[x]=1;
	for(int i=p[x];i ;i=e[i].nt){
		int t=e[i].b;
		if(!deep[t]){
			deep[t]=deep[x]+1;
			dfs(t);
			if(flag[t])flag[x]=1;
		}
	}
}

void solve(int x){
	printf("%d ",x);c[x]*=-1;
	for(int i=p[x];i;i=e[i].nt){
		int t=e[i].b;
		if(flag[t]&&deep[t]>deep[x]||x==1){
			solve(t);
			printf("%d ",x);c[x]*=-1;
			if(c[t]<0){
				printf("%d %d ",t,x);
			}
		}
	}
	if(x==1&&c[x]==-1){
		int t=e[p[1]].b;
		printf("%d %d %d",t,x,t);
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&c[i]);
	for(int i=1;i<n;i++){
		int aa,bb;
		scanf("%d%d",&aa,&bb);
		anode(aa,bb);
	}deep[1]=1;
	dfs(1);
	solve(1);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cmath>
#include <stack>
#include <string>
#define mod 1000000009
#define eps 1e-5
#define pi acos(-1)
#define N 200010
using namespace std;
typedef pair<int,int>pa;
typedef __int64 LL;
int c[N];
int n;
struct edge{
	int b,nt;
}e[N*2];

int p[N],nn;
void aedge(int x,int y){
	nn++;e[nn].b=y;e[nn].nt=p[x];p[x]=nn;
}

void anode(int x,int y){
	aedge(x,y);aedge(y,x);
}
int flag[N],deep[N];
void dfs(int x){
	if(c[x]==-1)flag[x]=1;
	for(int i=p[x];i ;i=e[i].nt){
		int t=e[i].b;
		if(!deep[t]){
			deep[t]=deep[x]+1;
			dfs(t);
			if(flag[t])flag[x]=1;
		}
	}
}

void solve(int x){
	printf("%d ",x);c[x]*=-1;
	for(int i=p[x];i;i=e[i].nt){
		int t=e[i].b;
		if(flag[t]&&deep[t]>deep[x]||x==1){
			solve(t);
			printf("%d ",x);c[x]*=-1;
			if(c[t]<0){
				printf("%d %d ",t,x);
			}
		}
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&c[i]);
	for(int i=1;i<n;i++){
		int aa,bb;
		scanf("%d%d",&aa,&bb);
		anode(aa,bb);
	}deep[1]=1;
	dfs(1);
	solve(1);
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const int maxn=2000000+100;
vector<int>G[maxn];
int color[maxn];
void put(int x)
{
    color[x]=-color[x];
    printf(" %d",x);
}
void dfs(int u,int pre)
{
    for(int i=0;i<G[u].size();i++)
    {
        int v=G[u][i];
        if(v==pre)
            continue;
        printf(" %d",v);
        color[v]=-color[v];

        dfs(v,u);

        printf(" %d",u);
        color[u]=-color[u];

        if(color[v]==-1)
        {
            put(v);
            put(u);
        }
    }
    if(u==1&&color[u]==-1)
    {
        int v=G[u][0];
        put(v);
        put(u);
        put(v);
    }
}
int main()
{
    int n;
    int u,v;
    while(scanf("%d",&n)!=-1)
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&color[i]);
        }

        for(int i=1;i<n;i++)
        {
            scanf("%d%d",&u,&v);
            G[u].push_back(v);
            G[v].push_back(u);
        }
        printf("1");
        dfs(1,1);

        puts("");
    }
    return 0;
}


#pragma comment(linker, "/stack:640000000")

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
const double PI=acos(-1.0);

#define    READ(f) 	         freopen(f, "r", stdin)
#define    WRITE(f)   	     freopen(f, "w", stdout)
#define    MP(x, y) 	     make_pair(x, y)
#define    PB(x)             push_back(x)
#define    rep(i,n)          for(int i = 1 ; i<=(n) ; i++)
#define    repI(i,n)         for(int i = 0 ; i<(n) ; i++)
#define    FOR(i,L,R) 	     for (int i = L; i <= R; i++)
#define    ROF(i,L,R) 	     for (int i = L; i >= R; i--)
#define    FOREACH(i,t)      for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define    ALL(p) 	         p.begin(),p.end()
#define    ALLR(p) 	         p.rbegin(),p.rend()
#define    SET(p) 	         memset(p, -1, sizeof(p))
#define    CLR(p)            memset(p, 0, sizeof(p))
#define    MEM(p, v)         memset(p, v, sizeof(p))
#define    getI(a) 	         scanf("%d", &a)
#define    getII(a,b) 	     scanf("%d%d", &a, &b)
#define    getIII(a,b,c)     scanf("%d%d%d", &a, &b, &c)
#define    getL(a)           scanf("%lld",&a)
#define    getLL(a,b)        scanf("%lld%lld",&a,&b)
#define    getLLL(a,b,c)     scanf("%lld%lld%lld",&a,&b,&c)
#define    getC(n)           scanf("%c",&n)
#define    getF(n)           scanf("%lf",&n)
#define    getS(n)           scanf("%s",n)
#define    bitCheck(a,k)     ((bool)(a&(1<<(k))))
#define    bitOff(a,k)       (a&(~(1<<(k))))
#define    bitOn(a,k)        (a|(1<<(k)))
#define    bitFlip(a,k)      (a^(1<<(k)))
#define    iseq(a,b)         (fabs(a-b)<EPS)
#define    vi 	 vector < int >
#define    vii 	 vector < vector < int > >
#define    pii 	 pair< int, int >
#define    ff 	 first
#define    ss 	 second
#define    ll	 long long
#define    ull 	 unsigned long long

template< class T > inline T _abs(T n) { return ((n) < 0 ? -(n) : (n)); }
template< class T > inline T _max(T a, T b) { return (!((a)<(b))?(a):(b)); }
template< class T > inline T _min(T a, T b) { return (((a)<(b))?(a):(b)); }
template< class T > inline T _swap(T &a, T &b) { a=a^b;b=a^b;a=a^b;}
template< class T > inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); }
template< class T > inline T lcm(T a, T b) { return ((a) / gcd((a), (b)) * (b)); }
template <typename T> string NumberToString ( T Number ) { ostringstream ss; ss << Number; return ss.str(); }

#ifdef mamun
     #define debug(args...) {cerr<<"*: "; dbg,args; cerr<<endl;}
#else
    #define debug(args...)  // Just strip off all debug tokens
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;
///****************** template ends here ****************
int t,n,m;
vector<int> adj[200005];
int arr[200005];
void func(int val)
{
    printf("%d ",val);
    arr[val]=-arr[val];
    debug(val,arr[val]);
}
void dfs(int src,int prev)
{
    func(src);
    repI(i,adj[src].size())
    {
        int v=adj[src][i];
        if(v==prev)continue;
        dfs(v,src);
        func(src);
        if(arr[v]==-1)
        {
            func(v);
            func(src);
        }
    }
    if(src==1&&arr[src]==-1)
    {
        func(adj[src][0]);
        func(src);
        func(adj[src][0]);
    }
}

int main() {
    ///check for 0 or -1 if input not specified
    #ifdef mamun
//        READ("in.txt");
//        WRITE("out.txt");
    #endif // mamun
//    ios_base::sync_with_stdio(0);cin.tie(0);

    getI(n);
    {
        int flag=1;
        CLR(arr);
        rep(i,n)
        {
            adj[i].clear();
            getI(arr[i]);
//            if(arr[i]==-1)arr[i]=0;
            if(arr[i]==-1)flag=0;
        }
        rep(i,n-1)
        {
            int x,y;
            getII(x,y);
            adj[x].PB(y);
            adj[y].PB(x);
        }
        if(flag==1)
        {
            puts("1");
            return 0;
        }
        dfs(1,-1);
        puts("");
//        rep(i,n)debug(arr[i])
    }

    return 0;
}


#pragma comment(linker, "/stack:640000000")

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
const double PI=acos(-1.0);

#define    READ(f) 	         freopen(f, "r", stdin)
#define    WRITE(f)   	     freopen(f, "w", stdout)
#define    MP(x, y) 	     make_pair(x, y)
#define    PB(x)             push_back(x)
#define    rep(i,n)          for(int i = 1 ; i<=(n) ; i++)
#define    repI(i,n)         for(int i = 0 ; i<(n) ; i++)
#define    FOR(i,L,R) 	     for (int i = L; i <= R; i++)
#define    ROF(i,L,R) 	     for (int i = L; i >= R; i--)
#define    FOREACH(i,t)      for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define    ALL(p) 	         p.begin(),p.end()
#define    ALLR(p) 	         p.rbegin(),p.rend()
#define    SET(p) 	         memset(p, -1, sizeof(p))
#define    CLR(p)            memset(p, 0, sizeof(p))
#define    MEM(p, v)         memset(p, v, sizeof(p))
#define    getI(a) 	         scanf("%d", &a)
#define    getII(a,b) 	     scanf("%d%d", &a, &b)
#define    getIII(a,b,c)     scanf("%d%d%d", &a, &b, &c)
#define    getL(a)           scanf("%lld",&a)
#define    getLL(a,b)        scanf("%lld%lld",&a,&b)
#define    getLLL(a,b,c)     scanf("%lld%lld%lld",&a,&b,&c)
#define    getC(n)           scanf("%c",&n)
#define    getF(n)           scanf("%lf",&n)
#define    getS(n)           scanf("%s",n)
#define    bitCheck(a,k)     ((bool)(a&(1<<(k))))
#define    bitOff(a,k)       (a&(~(1<<(k))))
#define    bitOn(a,k)        (a|(1<<(k)))
#define    bitFlip(a,k)      (a^(1<<(k)))
#define    iseq(a,b)         (fabs(a-b)<EPS)
#define    vi 	 vector < int >
#define    vii 	 vector < vector < int > >
#define    pii 	 pair< int, int >
#define    ff 	 first
#define    ss 	 second
#define    ll	 long long
#define    ull 	 unsigned long long

template< class T > inline T _abs(T n) { return ((n) < 0 ? -(n) : (n)); }
template< class T > inline T _max(T a, T b) { return (!((a)<(b))?(a):(b)); }
template< class T > inline T _min(T a, T b) { return (((a)<(b))?(a):(b)); }
template< class T > inline T _swap(T &a, T &b) { a=a^b;b=a^b;a=a^b;}
template< class T > inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); }
template< class T > inline T lcm(T a, T b) { return ((a) / gcd((a), (b)) * (b)); }
template <typename T> string NumberToString ( T Number ) { ostringstream ss; ss << Number; return ss.str(); }

#ifdef mamun
     #define debug(args...) {cerr<<"*: "; dbg,args; cerr<<endl;}
#else
    #define debug(args...)  // Just strip off all debug tokens
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;
///****************** template ends here ****************
int t,n,m;
vector<int> adj[200005];
int arr[200005];
void func(int val)
{
    printf("%d ",val);
    arr[val]=-arr[val];
//    debug(val,arr[val]);
}
void dfs(int src,int prev)
{
    if(src!=1)func(src);
    else printf("%d ",src);
    repI(i,adj[src].size())
    {
        int v=adj[src][i];
        if(v==prev)continue;
        dfs(v,src);
        func(src);
        if(arr[v]==-1)
        {
            func(v);
            func(src);
        }
    }
    if(src==1&&arr[src]==-1)
    {
        func(adj[src][0]);
        func(src);
        func(adj[src][0]);
    }
}

int main() {
    ///check for 0 or -1 if input not specified
    #ifdef mamun
//        READ("in.txt");
//        WRITE("out.txt");
    #endif // mamun
//    ios_base::sync_with_stdio(0);cin.tie(0);

    getI(n);
    {
        int flag=1;
        CLR(arr);
        rep(i,n)
        {
            adj[i].clear();
            getI(arr[i]);
//            if(arr[i]==-1)arr[i]=0;
            if(arr[i]==-1)flag=0;
        }
        rep(i,n-1)
        {
            int x,y;
            getII(x,y);
            adj[x].PB(y);
            adj[y].PB(x);
        }
        if(flag==1)
        {
            puts("1");
            return 0;
        }
        dfs(1,-1);
        puts("");
//        rep(i,n)debug(arr[i])
    }

    return 0;
}


#pragma comment(linker, "/stack:640000000")

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
const double PI=acos(-1.0);

#define    READ(f) 	         freopen(f, "r", stdin)
#define    WRITE(f)   	     freopen(f, "w", stdout)
#define    MP(x, y) 	     make_pair(x, y)
#define    PB(x)             push_back(x)
#define    rep(i,n)          for(int i = 1 ; i<=(n) ; i++)
#define    repI(i,n)         for(int i = 0 ; i<(n) ; i++)
#define    FOR(i,L,R) 	     for (int i = L; i <= R; i++)
#define    ROF(i,L,R) 	     for (int i = L; i >= R; i--)
#define    FOREACH(i,t)      for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define    ALL(p) 	         p.begin(),p.end()
#define    ALLR(p) 	         p.rbegin(),p.rend()
#define    SET(p) 	         memset(p, -1, sizeof(p))
#define    CLR(p)            memset(p, 0, sizeof(p))
#define    MEM(p, v)         memset(p, v, sizeof(p))
#define    getI(a) 	         scanf("%d", &a)
#define    getII(a,b) 	     scanf("%d%d", &a, &b)
#define    getIII(a,b,c)     scanf("%d%d%d", &a, &b, &c)
#define    getL(a)           scanf("%lld",&a)
#define    getLL(a,b)        scanf("%lld%lld",&a,&b)
#define    getLLL(a,b,c)     scanf("%lld%lld%lld",&a,&b,&c)
#define    getC(n)           scanf("%c",&n)
#define    getF(n)           scanf("%lf",&n)
#define    getS(n)           scanf("%s",n)
#define    bitCheck(a,k)     ((bool)(a&(1<<(k))))
#define    bitOff(a,k)       (a&(~(1<<(k))))
#define    bitOn(a,k)        (a|(1<<(k)))
#define    bitFlip(a,k)      (a^(1<<(k)))
#define    iseq(a,b)         (fabs(a-b)<EPS)
#define    vi 	 vector < int >
#define    vii 	 vector < vector < int > >
#define    pii 	 pair< int, int >
#define    ff 	 first
#define    ss 	 second
#define    ll	 long long
#define    ull 	 unsigned long long

template< class T > inline T _abs(T n) { return ((n) < 0 ? -(n) : (n)); }
template< class T > inline T _max(T a, T b) { return (!((a)<(b))?(a):(b)); }
template< class T > inline T _min(T a, T b) { return (((a)<(b))?(a):(b)); }
template< class T > inline T _swap(T &a, T &b) { a=a^b;b=a^b;a=a^b;}
template< class T > inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); }
template< class T > inline T lcm(T a, T b) { return ((a) / gcd((a), (b)) * (b)); }
template <typename T> string NumberToString ( T Number ) { ostringstream ss; ss << Number; return ss.str(); }

#ifdef mamun
     #define debug(args...) {cerr<<"*: "; dbg,args; cerr<<endl;}
#else
    #define debug(args...)  // Just strip off all debug tokens
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;
///****************** template ends here ****************
int t,n,m;
vector<int> adj[200005];
int arr[200005];
void func(int val)
{
    printf("%d ",val);
    arr[val]=1-arr[val];
}
void dfs(int src,int prev)
{
    func(src);
    int flag=0;
    repI(i,adj[src].size())
    {
        int v=adj[src][i];
        if(v==prev)continue;
        dfs(v,src);
        func(src);
        if(arr[v]==0)
        {
            func(v);
            func(src);
        }
    }
    if(src==1&&arr[src]==0)
    {
        func(adj[src][0]);
        func(src);
        func(adj[src][0]);
    }
}

int main() {
    ///check for 0 or -1 if input not specified
    #ifdef mamun
//        READ("in.txt");
//        WRITE("out.txt");
    #endif // mamun
//    ios_base::sync_with_stdio(0);cin.tie(0);

    getI(n);
    {
        int flag=1;
        rep(i,n)
        {
            getI(arr[i]);
            if(arr[i]==-1)arr[i]=0;
            if(!arr[0])flag=0;
        }
        rep(i,n-1)
        {
            int x,y;
            getII(x,y);
            adj[x].PB(y);
            adj[y].PB(x);
        }
        if(flag==1)
        {
            puts("1");
            return 0;
        }
        dfs(1,-1);
        puts("");
//        rep(i,n)debug(arr[i])
    }

    return 0;
}


#include <iostream>
#include <stack>
#include <vector>
#include <queue>
using namespace std;
int nodes[200001];
vector <int> adjlist[200001];
int par[200001];
queue <int> q;
vector <int> eulertour;
vector <int> walk;
stack <int> s;
stack <int> depths;
bool vis[200001];
int last[200001];
int n;
void getwalk() {
	for (int i = 1; i < eulertour.size(); i++) {
		nodes[eulertour[i]] = !nodes[eulertour[i]];
		if (!nodes[eulertour[i]] && last[eulertour[i]] == i) {
			if (eulertour[i] == 1) {

			}
			else {
				walk.push_back(eulertour[i]);
				walk.push_back(par[eulertour[i]]);
				walk.push_back(eulertour[i]);
				nodes[par[eulertour[i]]] = !nodes[par[eulertour[i]]];
			}
		} else {
			walk.push_back(eulertour[i]);
		}
	}

}

void getpar() {
	par[1] = -1;
	q.push(1);
	while (!q.empty()) {
		int curnode = q.front();
		q.pop();
		for (int i = 0; i < adjlist[curnode].size(); i++) {
			if (par[adjlist[curnode][i]] == 0) {
				par[adjlist[curnode][i]] = curnode;
				q.push(adjlist[curnode][i]);
			}
		}
	}
}

void geteulertour() {
	for (int i = 0; i <= n; i++)
		vis[i] = false;
	s.push(1);
	while (!s.empty()) {
		int curnode = s.top();
		//cout << curnode << '\n';
		s.pop();
		depths.push(curnode);
		eulertour.push_back(curnode);
		vis[curnode] = true;
		for (int i = 0; i < adjlist[curnode].size(); i++) {
			if (!vis[adjlist[curnode][i]])
				s.push(adjlist[curnode][i]);
		}
		if (!s.empty()) {
			while (par[s.top()] != depths.top()) {
				depths.pop();
				//cout << "CLIMB: " << depths.top() << ' ';
				eulertour.push_back(depths.top());
			}
		}
		/*cout << "EULER TOUR: ";
		for (int i = 0; i < eulertour.size(); i++) {
			cout << eulertour[i] << ' ';
		} cout << '\n';*/
	}
	depths.pop();
	while (!depths.empty()) {
		eulertour.push_back(depths.top());
		depths.pop();
	}
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> nodes[i];
		nodes[i] = (nodes[i] == -1 ? 0 : 1);
	}
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		adjlist[a].push_back(b);
		adjlist[b].push_back(a);
	}
	getpar();
	/*cout << "PARENTS: ";
	for (int i = 1; i <= n; i++) {
		cout << par[i] << ' ';
	} cout << '\n';*/
	geteulertour();
	/*cout << eulertour.size() << '\n';
	for (int i = 0; i < eulertour.size(); i++)
		cout << eulertour[i] << ' ';
	cout << '\n';*/
	for (int i = 0; i < eulertour.size(); i++) {
		last[eulertour[i]] = i;
	}
	getwalk();
	//cout << walk.size() << '\n';
	cout << 1 << ' ';
	for (int i = 0; i < walk.size(); i++) {
		cout << walk[i] << ' ';
	}
	cout << '\n';
}


#include <iostream>
#include <stack>
#include <vector>
#include <queue>
using namespace std;
int nodes[200001];
vector <int> adjlist[200001];
int par[200001];
queue <int> q;
vector <int> eulertour;
vector <int> walk;
stack <int> s;
stack <int> depths;
bool vis[200001];
int last[200001];
int n;
void getwalk() {
	for (int i = 1; i < eulertour.size(); i++) {
		nodes[eulertour[i]] = !nodes[eulertour[i]];
		if (!nodes[eulertour[i]] && last[eulertour[i]] == i) {
			if (eulertour[i] == 1) {

			}
			else {
				walk.push_back(eulertour[i]);
				walk.push_back(par[eulertour[i]]);
				walk.push_back(eulertour[i]);
				nodes[par[eulertour[i]]] = !nodes[par[eulertour[i]]];
			}
		} else {
			walk.push_back(eulertour[i]);
		}
	}

}

void getpar() {
	par[1] = -1;
	q.push(1);
	while (!q.empty()) {
		int curnode = q.front();
		q.pop();
		for (int i = 0; i < adjlist[curnode].size(); i++) {
			if (par[adjlist[curnode][i]] == 0) {
				par[adjlist[curnode][i]] = curnode;
				q.push(adjlist[curnode][i]);
			}
		}
	}
}

void geteulertour() {
	for (int i = 0; i <= n; i++)
		vis[i] = false;
	s.push(1);
	while (!s.empty()) {
		int curnode = s.top();
		cout << curnode << '\n';
		s.pop();
		depths.push(curnode);
		eulertour.push_back(curnode);
		vis[curnode] = true;
		for (int i = 0; i < adjlist[curnode].size(); i++) {
			if (!vis[adjlist[curnode][i]])
				s.push(adjlist[curnode][i]);
		}
		if (!s.empty()) {
			while (par[s.top()] != depths.top()) {
				depths.pop();
				//cout << "CLIMB: " << depths.top() << ' ';
				eulertour.push_back(depths.top());
			}
		}
		/*cout << "EULER TOUR: ";
		for (int i = 0; i < eulertour.size(); i++) {
			cout << eulertour[i] << ' ';
		} cout << '\n';*/
	}
	depths.pop();
	while (!depths.empty()) {
		eulertour.push_back(depths.top());
		depths.pop();
	}
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> nodes[i];
		nodes[i] = (nodes[i] == -1 ? 0 : 1);
	}
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		adjlist[a].push_back(b);
		adjlist[b].push_back(a);
	}
	getpar();
	/*cout << "PARENTS: ";
	for (int i = 1; i <= n; i++) {
		cout << par[i] << ' ';
	} cout << '\n';*/
	geteulertour();
	/*cout << eulertour.size() << '\n';
	for (int i = 0; i < eulertour.size(); i++)
		cout << eulertour[i] << ' ';
	cout << '\n';*/
	for (int i = 0; i < eulertour.size(); i++) {
		last[eulertour[i]] = i;
	}
	getwalk();
	//cout << walk.size() << '\n';
	cout << 1 << ' ';
	for (int i = 0; i < walk.size(); i++) {
		cout << walk[i] << ' ';
	}
	cout << '\n';
}


#include <stdio.h>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

const int MAXN = 2E5+10;
int color[MAXN];

vector <int> g[MAXN];

int used[MAXN];

int cur_out_time = 1;
int out_time[MAXN];
int back[MAXN];

int ncolor[MAXN];
vector <int> ng[MAXN];

void dfs(int v) {
	used[v] = 1;
	for (int i = 0; i < g[v].size(); i++) {
		int to = g[v][i];
		if (used[to] == 0) {
			dfs(to);
		}
	}
	out_time[v] = cur_out_time;
	cur_out_time++;
	return;
}

void Clear_Used() {
	for (int i = 0; i < MAXN; i++) {
		used[i] = 0;
	}
	return;
}

int l[MAXN];
int r[MAXN];

pair <int, int> dfs_l_r(int v) {
	used[v] = 1;
	int minv = v, maxv = v;
	for (int i = 0; i < ng[v].size(); i++) {
		int to = ng[v][i];
		if (used[to] == 0) {
			pair <int, int> tmp = dfs_l_r(to);
			minv = min(minv, tmp.first);
			maxv = max(maxv, tmp.second);
		}
	}
	l[v] = minv;
	r[v] = maxv;
	return make_pair(minv, maxv);
}

int parrent[MAXN];

void dfs_parrent(int v) {
	used[v] = 1;
	for (int i = 0; i < ng[v].size(); i++) {
		int to = ng[v][i];
		if (used[to] == 0) {
			parrent[to] = v;
			dfs_parrent(to);
		}
	}
	return;
}

set <int> need_to_color;
set <int>::iterator iter;

int ans[10000010]; int ans_size;

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &color[i]);
	}
	for (int i = 0 ; i < n-1; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		g[a].push_back(b);
		g[b].push_back(a);
	}

	bool is_clear_tree = true;
	for (int i = 1; i <= n; i++) {
		if (color[i] == -1) {
			is_clear_tree = false;
			break;
		}
	}
	if (is_clear_tree) {
		printf("1\n");
		return 0;
	}

	dfs(1);
	for (int i = 1; i <= n; i++) {
		ncolor[out_time[i]] = color[i];
		back[out_time[i]] = i;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < g[i].size(); j++) {
			int b = g[i][j];
			ng[out_time[i]].push_back(out_time[b]);
		}
	}
	Clear_Used();
	dfs_l_r(out_time[1]);
	Clear_Used();
	dfs_parrent(out_time[1]);
	Clear_Used();

	for (int i = 1; i <= n; i++) {
		if (ncolor[i] == -1) {
			need_to_color.insert(i);
		}
	}

	int cur_v = out_time[1];
	while (need_to_color.size() != 0) {
		int to = *(need_to_color.begin());

		if (to > cur_v) {
			ans[ans_size++] = cur_v;
			cur_v = parrent[cur_v];

			ncolor[cur_v] *= -1;
			if (ncolor[cur_v] == 1) {
				need_to_color.erase(need_to_color.find(cur_v));
			}
			else {
				need_to_color.insert(cur_v);
			}
			continue;
		}
		if (to == cur_v) {
			if (need_to_color.size() > 1) {
				iter = need_to_color.begin();
				iter++;

				to = *iter;

				if (to > cur_v) {
					ans[ans_size++] = cur_v;
					cur_v = parrent[cur_v];

					ncolor[cur_v] *= -1;
					if (ncolor[cur_v] == 1) {
						need_to_color.erase(need_to_color.find(cur_v));
					}
					else {
						need_to_color.insert(cur_v);
					}
					continue;
				}

				if (to < cur_v) {
					int prev_vertex = cur_v;
					for (int i = 0; i < ng[cur_v].size(); i++) {
						if (parrent[cur_v] != ng[cur_v][i]) {
							int vertex_on_next_step = ng[cur_v][i];
							if (to >= l[vertex_on_next_step] && to <= r[vertex_on_next_step]) {
								cur_v = vertex_on_next_step;
								break;
							}
						}
					}

					ans[ans_size++] = prev_vertex;

					ncolor[cur_v] *= -1;
					if (ncolor[cur_v] == 1) {
						need_to_color.erase(need_to_color.find(cur_v));
					}
					else {
						need_to_color.insert(cur_v);
					}
					continue;
				}

			}
			continue;
		}
		if (to < cur_v) {
			int prev_vertex = cur_v;
			for (int i = 0; i < ng[cur_v].size(); i++) {
				if (parrent[cur_v] != ng[cur_v][i]) {
					int vertex_on_next_step = ng[cur_v][i];
					if (to >= l[vertex_on_next_step] && to <= r[vertex_on_next_step]) {
						cur_v = vertex_on_next_step;
						break;
					}
				}
			}

			ans[ans_size++] = prev_vertex;
			ncolor[cur_v] *= -1;
			if (ncolor[cur_v] == 1) {
				need_to_color.erase(need_to_color.find(cur_v));
			}
			else {
				need_to_color.insert(cur_v);
			}
			continue;
		}
	}

	for (int i = 0; i < ans_size; i++) {
		ans[i] = back[ans[i]];
	}

	ans[ans_size++] = back[cur_v];

	for (int i = 0; i < ans_size-1; i++) {
		printf("%d ", ans[i]);
	}
	printf("%d\n", ans[ans_size-1]);

	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int n;
const int MAXN = 2E5+10;
int color[MAXN];

vector <int> g[MAXN];

int used[MAXN];

int cur_out_time = 1;
int out_time[MAXN];
int back[MAXN];

int ncolor[MAXN];
vector <int> ng[MAXN];

void dfs(int v) {
	used[v] = 1;
	for (int i = 0; i < g[v].size(); i++) {
		int to = g[v][i];
		if (used[to] == 0) {
			dfs(to);
		}
	}
	out_time[v] = cur_out_time;
	cur_out_time++;
	return;
}

void Clear_Used() {
	for (int i = 0; i <= n; i++) {
		used[i] = 0;
	}
	return;
}

int l[MAXN];
int r[MAXN];

void dfs_l_r(int v) {
	used[v] = 1;
	int minv = v, maxv = v;
	for (int i = 0; i < ng[v].size(); i++) {
		int to = ng[v][i];
		if (used[to] == 0) {
			dfs_l_r(to);
			minv = min(minv, l[to]);
			maxv = max(maxv, r[to]);
		}
	}
	l[v] = minv;
	r[v] = maxv;
	return;
}

int parrent[MAXN];

void dfs_parrent(int v) {
	used[v] = 1;
	for (int i = 0; i < ng[v].size(); i++) {
		int to = ng[v][i];
		if (used[to] == 0) {
			parrent[to] = v;
			dfs_parrent(to);
		}
	}
	return;
}

set <int> need_to_color;
set <int>::iterator iter;

int ans[10000010]; int ans_size;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &color[i]);
	}
	for (int i = 0 ; i < n-1; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		g[a].push_back(b);
		g[b].push_back(a);
	}

	bool is_clear_tree = true;
	for (int i = 1; i <= n; i++) {
		if (color[i] == -1) {
			is_clear_tree = false;
			break;
		}
	}
	if (is_clear_tree) {
		printf("1\n");
		return 0;
	}

	dfs(1);
	for (int i = 1; i <= n; i++) {
		ncolor[out_time[i]] = color[i];
		back[out_time[i]] = i;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < g[i].size(); j++) {
			int b = g[i][j];
			ng[out_time[i]].push_back(out_time[b]);
		}
	}
	Clear_Used();
	dfs_l_r(out_time[1]);
	Clear_Used();
	dfs_parrent(out_time[1]);
	Clear_Used();

	for (int i = 1; i <= n; i++) {
		if (ncolor[i] == -1) {
			need_to_color.insert(i);
		}
	}

	int cur_v = out_time[1];
	while (need_to_color.size() != 0) {
		int to = *(need_to_color.begin());

		if (to > cur_v) {
			ans[ans_size++] = cur_v;
			cur_v = parrent[cur_v];

			ncolor[cur_v] *= -1;
			if (ncolor[cur_v] == 1) {
				need_to_color.erase(need_to_color.find(cur_v));
			}
			else {
				need_to_color.insert(cur_v);
			}
			continue;
		}
		if (to == cur_v) {
			if (need_to_color.size() > 1) {
				iter = need_to_color.begin();
				iter++;

				to = *iter;

				if (to > cur_v) {
					ans[ans_size++] = cur_v;
					cur_v = parrent[cur_v];

					ncolor[cur_v] *= -1;
					if (ncolor[cur_v] == 1) {
						need_to_color.erase(need_to_color.find(cur_v));
					}
					else {
						need_to_color.insert(cur_v);
					}
					continue;
				}

				if (to < cur_v) {
					int prev_vertex = cur_v;
					for (int i = 0; i < ng[cur_v].size(); i++) {
						if (parrent[cur_v] != ng[cur_v][i]) {
							int vertex_on_next_step = ng[cur_v][i];
							if (to >= l[vertex_on_next_step] && to <= r[vertex_on_next_step]) {
								cur_v = vertex_on_next_step;
								break;
							}
						}
					}

					ans[ans_size++] = prev_vertex;

					ncolor[cur_v] *= -1;
					if (ncolor[cur_v] == 1) {
						need_to_color.erase(need_to_color.find(cur_v));
					}
					else {
						need_to_color.insert(cur_v);
					}
					continue;
				}

			}
			continue;
		}
		if (to < cur_v) {
			int prev_vertex = cur_v;
			for (int i = 0; i < ng[cur_v].size(); i++) {
				if (parrent[cur_v] != ng[cur_v][i]) {
					int vertex_on_next_step = ng[cur_v][i];
					if (to >= l[vertex_on_next_step] && to <= r[vertex_on_next_step]) {
						cur_v = vertex_on_next_step;
						break;
					}
				}
			}

			ans[ans_size++] = prev_vertex;
			ncolor[cur_v] *= -1;
			if (ncolor[cur_v] == 1) {
				need_to_color.erase(need_to_color.find(cur_v));
			}
			else {
				need_to_color.insert(cur_v);
			}
			continue;
		}
	}

	for (int i = 0; i < ans_size; i++) {
		ans[i] = back[ans[i]];
	}

	ans[ans_size++] = back[cur_v];

	for (int i = 0; i < ans_size-1; i++) {
		printf("%d ", ans[i]);
	}
	printf("%d\n", ans[ans_size-1]);

	return 0;
}