#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];

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() {
	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;
				}
			}

			else {
				to = ng[cur_v][0];

				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;

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_s("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf_s("%d", &color[i]);
	}
	for (int i = 0 ; i < n-1; i++) {
		int a, b;
		scanf_s("%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 <iostream>
#include <vector>

using namespace std;

class node {
   public :
        int color;
        int pinks;
        vector<int> child;
};

int deepW(int ind, node *v, bool* seen) {
    seen[ind] = true;
    v[ind].pinks = 0;
    if (v[ind].child.size() == 0) return v[ind].color == 1 ? 0 : 1;
    for(vector<int>::iterator i = v[ind].child.begin(); i != v[ind].child.end(); ++i) {
        if (!seen[*i]) v[ind].pinks += deepW(*i,v,seen);
    }
    return v[ind].pinks + (v[ind].color == 1 ? 0 : 1);
}

void deep(int ind, int father, node *v) {
    v[ind].color *= -1;
    v[ind].pinks = 0;
    cout << ind << " ";
    for(vector<int>::iterator i = v[ind].child.begin(); i != v[ind].child.end(); ++i) {
        if ((*i) != father) {
            if(v[*i].pinks > 0) {
                deep(*i, ind, v);
                v[ind].color *= -1;
                cout << ind << " ";
            }
        }
    }
    for(vector<int>::iterator i = v[ind].child.begin(); i != v[ind].child.end(); ++i) {
    if ((*i != father) && (v[*i].color == -1)) {
                    deep(*i, ind, v);
                    v[ind].color *= -1;
                    cout << ind << " ";
            }
    }

}

int main()
{
    int n;
    cin >> n;
    node v[n+1];
    bool seen[n+1];
    for(int i = 1; i <= n; ++i) {
        cin >> v[i].color;
        seen[i] = false;
    }
    for(int i = 1; i < n; ++i) {
        int x,y;
        cin >> x >> y;
        v[y].child.push_back(x);
        v[x].child.push_back(y);
    }
    if (deepW(1,v,seen) == 0) {
        cout << "1";
        return 0;
    }
    v[1].color *= -1;
    deep(1,0,v);
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int n;

class node {
   public :
        int color;
        int pinks;
        vector<int> child;
};

int deepW(int ind, node *v, bool* seen) {
    seen[ind] = true;
    v[ind].pinks = 0;
    if (v[ind].child.size() == 0) return v[ind].color == 1 ? 0 : 1;
    for(vector<int>::iterator i = v[ind].child.begin(); i != v[ind].child.end(); ++i) {
        if (!seen[*i]) v[ind].pinks += deepW(*i,v,seen);
    }
    return v[ind].pinks + (v[ind].color == 1 ? 0 : 1);
}

bool check(node *v) {
        for(int i = 1; i <= n; ++i) {
            if (v[i].color == -1) return false;
        }
        return true;
}

bool deep(int ind, int father, node *v) {
    v[ind].color *= -1;
    v[ind].pinks = 0;
    cout << ind << " ";
    for(vector<int>::iterator i = v[ind].child.begin(); i != v[ind].child.end(); ++i) {
        if ((*i) != father) {
            if(v[*i].pinks > 0) {
                if(deep(*i, ind, v)) return true;
                v[ind].color *= -1;
                cout << ind << " ";
            }
        }
    }
    for(vector<int>::iterator i = v[ind].child.begin(); i != v[ind].child.end(); ++i) {
    if ((*i != father) && (v[*i].color == -1)) {
                    if(deep(*i, ind, v)) return true;
                    v[ind].color *= -1;
                    cout << ind << " ";
            }
    }
    return check(v);
}

int main()
{
    cin >> n;
    node v[n+1];
    bool seen[n+1];
    for(int i = 1; i <= n; ++i) {
        cin >> v[i].color;
        seen[i] = false;
    }
    for(int i = 1; i < n; ++i) {
        int x,y;
        cin >> x >> y;
        v[y].child.push_back(x);
        v[x].child.push_back(y);
    }
    if (deepW(1,v,seen) == 0) {
        if(v[1].color != -1) {
            cout << "1";
            return 0;
        }
    }
    if(v[1].color == -1) {
        cout << "1 " << v[1].child.at(0) <<" ";
        v[1].color = 1;
        v[v[1].child.at(0)].color *= -1;
    }
    if(!check(v)){
         v[1].color *= -1;
         deep(1,0,v);
    }

    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

class node {
   public :
        int color;
        int pinks;
        vector<int> child;
};

int deepW(int ind, node *v, bool* seen) {
    seen[ind] = true;
    v[ind].pinks = 0;
    if (v[ind].child.size() == 0) return v[ind].color == 1 ? 0 : 1;
    for(vector<int>::iterator i = v[ind].child.begin(); i != v[ind].child.end(); ++i) {
        if (!seen[*i]) v[ind].pinks += deepW(*i,v,seen);
    }
    return v[ind].pinks + (v[ind].color == 1 ? 0 : 1);
}

void deep(int ind, int father, node *v) {
    v[ind].color *= -1;
    cout << ind << " ";
    for(vector<int>::iterator i = v[ind].child.begin(); i != v[ind].child.end(); ++i) {
        if ((*i) != father) {
            if(v[*i].pinks > 0) {
                deep(*i, ind, v);
                cout << ind << " ";
            }
            else if (v[*i].color == -1) {
                    deep(*i, ind, v);
                    cout << ind << " ";
            }
        }
    }
}

int main()
{
    int n;
    cin >> n;
    node v[n+1];
    bool seen[n+1];
    for(int i = 1; i <= n; ++i) {
        cin >> v[i].color;
        seen[i] = false;
    }
    for(int i = 1; i < n; ++i) {
        int x,y;
        cin >> x >> y;
        v[y].child.push_back(x);
        v[x].child.push_back(y);
    }
    if (deepW(1,v,seen) == 0) {
        cout << "1";
        return 0;
    }
    deep(1,0,v);
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

class node {
   public :
        int color;
        int pinks;
        vector<int> child;
};

int deepW(int ind, node *v, bool* seen) {
    seen[ind] = true;
    v[ind].pinks = 0;
    if (v[ind].child.size() == 0) return v[ind].color == 1 ? 0 : 1;
    for(vector<int>::iterator i = v[ind].child.begin(); i != v[ind].child.end(); ++i) {
        if (!seen[*i]) v[ind].pinks += deepW(*i,v,seen);
    }
    return v[ind].pinks + (v[ind].color == 1 ? 0 : 1);
}

void deep(int ind, int father, node *v) {
    v[ind].color *= -1;
    v[ind].pinks = 0;
    cout << ind << " ";
    for(vector<int>::iterator i = v[ind].child.begin(); i != v[ind].child.end(); ++i) {
        if ((*i) != father) {
            if(v[*i].pinks > 0) {
                deep(*i, ind, v);
                v[ind].color *= -1;
                cout << ind << " ";
            }
        }
    }
    for(vector<int>::iterator i = v[ind].child.begin(); i != v[ind].child.end(); ++i) {
    if ((*i != father) && (v[*i].color == -1)) {
                    deep(*i, ind, v);
                    v[ind].color *= -1;
                    cout << ind << " ";
            }
    }

}

int main()
{
    int n;
    cin >> n;
    node v[n+1];
    bool seen[n+1];
    for(int i = 1; i <= n; ++i) {
        cin >> v[i].color;
        seen[i] = false;
    }
    for(int i = 1; i < n; ++i) {
        int x,y;
        cin >> x >> y;
        v[y].child.push_back(x);
        v[x].child.push_back(y);
    }
    if (deepW(1,v,seen) == 0) {
        cout << "1";
        return 0;
    }
    //v[1].color *= -1;
    deep(1,0,v);
    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define mp make_pair
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const int N = 200200;

using namespace std;

vector < int > ans, v[N];
int n, a[N];

void dfs(int x, int p)
{
    if(v[x].size() == 1 && p != -1){
        if(a[x] == -1){
            ans.pb(x);
            ans.pb(p);
            a[x] = -a[x];
            a[p] = -a[p];
        }
        return;
    }
    ans.pb(x);
    a[x] = -a[x];
    for(int i = 0; i < v[x].size(); i++){
        int y = v[x][i];
        if(y == p)
            continue;
        dfs(y, x);
        if(a[y] == -1){
            ans.pb(y);
            ans.pb(x);
            a[y] = -a[y];
            a[x] = -a[x];
        }
    }
    if(p != -1){
        ans.pb(p);
        a[p] = -a[p];
    }
}

int main()
{
    //fin("input.txt");
    //fout("output.txt");
    ios_base::sync_with_stdio(0);
    cin >> n;
    bool l = true;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i] == -1)
            l = false;
    }
    for(int i = 1; i < n; i++){
        int x, y;
        cin >> x >> y;
        v[x].pb(y);
        v[y].pb(x);
    }
    if(l){
        cout << 1 << endl;
        return 0;
    }
    dfs(1, -1);
    for(int i = 0; i < ans.size(); i++)
        cout << ans[i] << " ";
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define mp make_pair
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const int N = 200200;

using namespace std;

vector < int > ans, v[N];
int n, a[N];

void dfs(int x, int p)
{
    if(v[x].size() == 1 && p != -1){
        if(a[x] == -1){
            ans.pb(x);
            ans.pb(p);
            a[x] = -a[x];
            a[p] = -a[p];
        }
        return;
    }
    ans.pb(x);
    a[x] = -a[x];
    for(int i = 0; i < v[x].size(); i++){
        int y = v[x][i];
        if(y == p)
            continue;
        dfs(y, x);
        if(a[y] == -1){
            ans.pb(y);
            ans.pb(x);
            a[y] = -a[y];
            a[x] = -a[x];
        }
    }
    if(p != -1){
        ans.pb(p);
        a[p] = -a[p];
    }
}

int main()
{
    //fin("input.txt");
    //fout("output.txt");
    ios_base::sync_with_stdio(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i < n; i++){
        int x, y;
        cin >> x >> y;
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs(1, -1);
    for(int i = 0; i < ans.size(); i++)
        cout << ans[i] << " ";
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define mp make_pair
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const int N = 200200;

using namespace std;

vector < int > ans, v[N];
int n, a[N];

void dfs(int x, int p)
{
    ans.pb(x);
    a[x] = -a[x];
    for(int i = 0; i < v[x].size(); i++){
        int y = v[x][i];
        if(y == p)
            continue;
        dfs(y, x);
        if(a[y] == -1){
            ans.pb(y);
            ans.pb(x);
            a[y] = -a[y];
            a[x] = -a[x];
        }
    }
    if(p != -1){
        ans.pb(p);
        a[p] = -a[p];
    }
}

int main()
{
    //fin("input.txt");
    //fout("output.txt");
    ios_base::sync_with_stdio(0);
    cin >> n;
    bool l = true;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i] == -1)
            l = false;
    }
    for(int i = 1; i < n; i++){
        int x, y;
        cin >> x >> y;
        v[x].pb(y);
        v[y].pb(x);
    }
    if(l){
        cout << 1;
        return 0;
    }
    dfs(1, -1);
    for(int i = 0; i < ans.size(); i++)
        cout << ans[i] << " ";
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define mp make_pair
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const int N = 200200;

using namespace std;

vector < int > ans, v[N];
int n, a[N];

void dfs(int x, int p)
{
    ans.pb(x);
    a[x] = -a[x];
    for(int i = 0; i < v[x].size(); i++){
        int y = v[x][i];
        if(y == p)
            continue;
        dfs(y, x);
        if(a[y] == -1){
            ans.pb(y);
            ans.pb(x);
            a[y] = -a[y];
            a[x] = -a[x];
        }
    }
    if(p)
        ans.pb(p);
    a[p] = -a[p];
}

int main()
{
    //fin("input.txt");
    //fout("output.txt");
    ios_base::sync_with_stdio(0);
    cin >> n;
    bool l = true;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i] == -1)
            l = false;
    }
    for(int i = 1; i < n; i++){
        int x, y;
        cin >> x >> y;
        v[x].pb(y);
        v[y].pb(x);
    }
    if(l){
        cout << 1;
        return 0;
    }
    dfs(1, 0);
    if(a[1] == 1){
        ans.pb(v[1][0]);
        ans.pb(1);
        ans.pb(v[1][0]);
    }
    for(int i = 0; i < ans.size(); i++)
        cout << ans[i] << " ";
}


#include <stdio.h>
#include <vector>
using namespace std;

const int MAX = 2e5 + 1;
int n, col[MAX], sum[MAX], u, v, cnt;
bool hasPink[MAX];
vector <int> adj[MAX];

void visit1(const int& u = 1, const int& par = 0) {
	for (int v : adj[u])
		if (v != par) {
			visit1(v, u);
			if (hasPink[v])
				hasPink[u] = true;
		}

	if (col[u] == 0)
		hasPink[u] = true;
}

void visit2(const int& u = 1, const int& par = 0) {
	for (int v : adj[u])
		if (v != par && hasPink[v]) {
			if (cnt == n)
				return;

			printf(" %d", v);
			if ((col[v] = 1 - col[v]) == 1)
				++cnt;
			else
				--cnt;
			visit2(v, u);

			if (cnt == n)
				return;

			if (col[v] == 0) {
				++cnt;
				col[v] = 1;
				printf(" %d", v);

				if (cnt == n)
					return;
				printf(" %d", u);
				if ((col[u] = 1 - col[u]) == 1)
					++cnt;
				else
					--cnt;
			}
		}
	if (cnt == n)
		return;

	if (par > 0) {
		printf(" %d", par);
		if ((col[par] = 1 - col[par]) == 1)
			++cnt;
		else
			--cnt;
	}
}

int main() {
	//freopen("in.txt", "r", stdin);
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", col + i);
		if (col[i] == -1)
			col[i] = 0;
		cnt += (col[i] == 1);
	}
	for (int i = 1; i < n; ++i) {
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	if (cnt == n) {
		printf("1");
		return 0;
	}

	visit1();
	printf("1");
	visit2();
	if (col[1] == 0) {
		int v = adj[1][0];
		printf(" %d 1 %d", v, v);
	}

	return 0;
}


#include <stdio.h>
#include <vector>
using namespace std;

const int MAX = 2e5 + 1;
int n, col[MAX], sum[MAX], u, v, cnt;
bool hasPink[MAX];
vector <int> adj[MAX];

void visit1(const int& u = 1, const int& par = 0) {
	for (int v : adj[u])
		if (v != par) {
			visit1(v, u);
			if (hasPink[v])
				hasPink[u] = true;
		}

	if (col[u] == 0)
		hasPink[u] = true;
}

void visit2(const int& u = 1, const int& par = 0) {
	for (int v : adj[u])
		if (v != par && hasPink[v]) {
			if (cnt == n)
				return;

			printf(" %d", v);
			if ((col[v] = 1 - col[v]) == 1)
				++cnt;
			else
				--cnt;
			visit2(v, u);

			if (cnt == n)
				return;

			if (col[v] == 0) {
				++cnt;
				printf(" %d %d", v, u);
				if ((col[u] = 1 - col[u]) == 1)
					++cnt;
				else
					--cnt;
			}
		}
	if (cnt == n)
		return;

	if (par > 0) {
		printf(" %d", par);
		if ((col[par] = 1 - col[par]) == 1)
			++cnt;
		else
			--cnt;
	}
}

int main() {
	//freopen("in.txt", "r", stdin);
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", col + i);
		if (col[i] == -1)
			col[i] = 0;
		cnt += (col[i] == 1);
	}
	for (int i = 1; i < n; ++i) {
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	if (cnt == n) {
		printf("1");
		return 0;
	}

	visit1();
	printf("1");
	visit2();

	return 0;
}


#include <stdio.h>
#include <vector>
using namespace std;

const int MAX = 2e5 + 1;
int n, col[MAX], sum[MAX], u, v, cnt;
bool hasPink[MAX];
vector <int> adj[MAX];

void visit1(const int& u = 1, const int& par = 0) {
	for (int v : adj[u])
		if (v != par) {
			visit1(v, u);
			if (hasPink[v])
				hasPink[u] = true;
		}

	if (col[u] == 0)
		hasPink[u] = true;
}

void visit2(const int& u = 1, const int& par = 0) {
	for (int v : adj[u])
		if (v != par && hasPink[v]) {
			if (cnt == n)
				return;

			printf(" %d", v);
			if ((col[v] = 1 - col[v]) == 1)
				++cnt;
			else
				--cnt;
			visit2(v, u);

			if (cnt == n)
				return;

			if (col[v] == 0) {
				++cnt;
				col[v] = 1;
				printf(" %d", v);

				if (cnt == n)
					return;
				printf(" %d", u);
				if ((col[u] = 1 - col[u]) == 1)
					++cnt;
				else
					--cnt;
			}
		}
	if (cnt == n)
		return;

	if (par > 0) {
		printf(" %d", par);
		if ((col[par] = 1 - col[par]) == 1)
			++cnt;
		else
			--cnt;
	}
}

int main() {
	//freopen("in.txt", "r", stdin);
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", col + i);
		if (col[i] == -1)
			col[i] = 0;
		cnt += (col[i] == 1);
	}
	for (int i = 1; i < n; ++i) {
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	if (cnt == n) {
		printf("1");
		return 0;
	}

	visit1();
	printf("1");
	visit2();

	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

struct BIT{
    int n;
    vector<int> t;
    BIT(){}
    BIT(int _n):n(_n+1), t(_n+1){}
    void add(int k, int val){
        k++;
        while(k < n){
            t[k] += val;
            k += (k&-k);
        }
    }
    int sum(int k){
        int r = 0;
        while(k > 0){
            r += t[k];
            k -= (k&-k);
        }
        return r;
    }
    int sum(int l, int r){
        return sum(r) - sum(l);
    }
};

class EulerTour {
    int now, V;
    vector<int> disc, bye;
    void dfs(const vector<vector<int> > &g, int u, int pre) {
        disc[u] = now++;
        for(int v : g[u]) if(v != pre) {
            dfs(g, v, u);
        }
        bye[u] = now++;
    }
public:
    vector<int> i2v, v2i;
    EulerTour(){}
    EulerTour(const vector<vector<int> > &graph, int root = 0) {
        V = (int)graph.size();
        now = 0;
        disc = bye = i2v = v2i = vector<int>(V);
        dfs(graph, root, -1);
        vector<pair<int, int> > vp(graph.size());
        for(int i = 0; i < V; i++) {
            vp[i] = make_pair(disc[i], i);
        }
        sort(vp.begin(), vp.end());
        for(int i = 0; i < V; ++i) {
            int v = vp[i].second;
            i2v[i] = v;
            v2i[v] = i;
        }
    }
    pair<int, int> range(int u) {
        int l = v2i[u], mid, lb = l, ub = V;
        while(ub - lb > 1) {
            mid = (lb + ub) >> 1;
            (disc[i2v[mid]] < bye[u] ? lb : ub) = mid;
        }
        return make_pair(l, ub);
    }
};

vi ans;
void dfs(int u, int p, vector<vi> &G, EulerTour &et, BIT &sm, vi &c) {
    ans.push_back(u+1);
    c[u] = !c[u];
    sm.add(et.v2i[u], c[u] ? -1 : 1);

    each(v, G[u]) if(v != p) {
        int l, r;
        tie(l, r) = et.range(v);
        while(sm.sum(l, r)) {
            dfs(v, u, G, et, sm, c);
            ans.push_back(u + 1);
            c[u] = !c[u];
            sm.add(et.v2i[u], c[u] ? -1 : 1);
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<vi> G(n);
    BIT sm(n);
    vi c(n);
    rep(i, n) {
        cin >> c[i];
        if(c[i] == -1)c[i] = 0;
    }

    rep(i, n - 1) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    c[0] = !c[0];
    EulerTour et(G);
    rep(v, n) {
        if(!c[v]) {
            sm.add(et.v2i[v], 1);
        }
    }

    dfs(0, -1, G, et, sm, c);

    if(!c[0]) {
        for(int v : {G[0][0]+1, 1, G[0][0]+1})ans.push_back(v);
    }

    rep(i, sz(ans))cout << ans[i] << (i != sz(ans) - 1 ? ' ' : '\n');
}


#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

struct BIT{
    int n;
    vector<int> t;
    BIT(){}
    BIT(int _n):n(_n+1), t(_n+1){}
    void add(int k, int val){
        k++;
        while(k < n){
            t[k] += val;
            k += (k&-k);
        }
    }
    int sum(int k){
        int r = 0;
        while(k > 0){
            r += t[k];
            k -= (k&-k);
        }
        return r;
    }
    int sum(int l, int r){
        return sum(r) - sum(l);
    }
};

class EulerTour {
    int now, V;
    vector<int> disc, bye;
    void dfs(const vector<vector<int> > &g, int u, int pre) {
        disc[u] = now++;
        for(int v : g[u]) if(v != pre) {
            dfs(g, v, u);
        }
        bye[u] = now++;
    }
public:
    vector<int> i2v, v2i;
    EulerTour(){}
    EulerTour(const vector<vector<int> > &graph, int root = 0) {
        V = (int)graph.size();
        now = 0;
        disc = bye = i2v = v2i = vector<int>(V);
        dfs(graph, root, -1);
        vector<pair<int, int> > vp(graph.size());
        for(int i = 0; i < V; i++) {
            vp[i] = make_pair(disc[i], i);
        }
        sort(vp.begin(), vp.end());
        for(int i = 0; i < V; ++i) {
            int v = vp[i].second;
            i2v[i] = v;
            v2i[v] = i;
        }
    }
    pair<int, int> range(int u) {
        int l = v2i[u], mid, lb = l, ub = V;
        while(ub - lb > 1) {
            mid = (lb + ub) >> 1;
            (disc[i2v[mid]] < bye[u] ? lb : ub) = mid;
        }
        return make_pair(l, ub);
    }
};

vi ans;
void dfs(int u, int p, vector<vi> &G, EulerTour &et, BIT &sm, vi &c) {
    ans.push_back(u+1);
    c[u] = !c[u];
    sm.add(et.v2i[u], c[u] ? -1 : 1);
    while(1) {
        int upd = 0;
        each(v, G[u]) if(v != p) {
            int l, r;
            tie(l, r) = et.range(v);
            if(sm.sum(l, r)) {
                dfs(v, u, G, et, sm, c);
                ans.push_back(u + 1);
                c[u] = !c[u];
                sm.add(et.v2i[u], c[u] ? -1 : 1);
                upd = 1;
            }
        }
        if(!upd)break;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<vi> G(n);
    BIT sm(n);
    vi c(n);
    rep(i, n) {
        cin >> c[i];
        if(c[i] == -1)c[i] = 0;
    }

    rep(i, n - 1) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    c[0] = !c[0];
    EulerTour et(G);
    rep(v, n) {
        if(!c[v]) {
            sm.add(et.v2i[v], 1);
        }
    }

    dfs(0, -1, G, et, sm, c);

    if(!c[0]) {
        for(int v : {G[0][0], 0, G[0][0]})ans.push_back(v);
    }

    rep(i, sz(ans))cout << ans[i] << (i != sz(ans) - 1 ? ' ' : '\n');
}


#include<bits/stdc++.h>
using namespace std;
#define Sd(a) scanf("%d",&a)

int n,arr[200005],a,b,par[200005],pink[200005],visited[200005],en[200005];
vector<int> vec[200005],ans;
int dfs(int x)
{
	int flg=0;
	visited[x]=1;

	for (int i = 0; i < (int)vec[x].size(); ++i)
		if(!visited[vec[x][i]])
		{
			par[vec[x][i]]=x;
			flg=flg|dfs(vec[x][i]);
		}

	if(arr[x]==-1)
		flg=1;

	pink[x]=flg;

	return flg;
}

void path(int x)
{
	int flg=0;
	visited[x]=1;
	ans.push_back(x);
	en[x]++;

	for (int i = 0; i < (int)vec[x].size(); ++i)
	{
		if(!visited[vec[x][i]])
			if(pink[vec[x][i]])
			{
				flg=1;
				path(vec[x][i]);
				ans.push_back(x);
				en[x]++;
			}
	}

	if(((x!=1)&&(en[x]%2)&&(arr[x]==1))||((x!=1)&&(en[x]%2==0)&&(arr[x]==-1)))
	{
		ans.push_back(par[x]);
		ans.push_back(x);
		en[x]++;
		en[par[x]]++;
	}

	if(((x==1)&&(en[1]%2==0)&&arr[1]==-1)||((x==1)&&(en[1]%2)&&(arr[1]==1)))
	{
		en[1]--;
		ans.pop_back();
	}
}

int main()
{
	cin>>n;

	for (int i = 1; i <= n; ++i)
		Sd(arr[i]);

	for (int i = 0; i < n-1; ++i)
	{
		Sd(a);Sd(b);
		vec[a].push_back(b);
		vec[b].push_back(a);
	}

	par[1]=1;
	dfs(1);
	memset(visited,0,sizeof(visited));
	en[1]=-1;

	if(arr[1]==-1)
	{
		int flgg=0;
		for (int i = 0; i < (int)vec[1].size(); ++i)
			if(pink[vec[1][i]])
				flgg=1;

		if(flgg==0)
		{
			cout<<1<<" "<<vec[1][0]<<" "<<1<<" "<<vec[1][0]<<endl;
			return 0;
		}
	}
	path(1);

	for (int i = 0; i < (int)ans.size(); ++i)
		cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Sd(a) scanf("%d",&a)

int n,arr[200005],a,b,par[200005],pink[200005],visited[200005],en[200005];
vector<int> vec[200005],ans;
int dfs(int x)
{
	int flg=0;
	visited[x]=1;

	for (int i = 0; i < (int)vec[x].size(); ++i)
		if(!visited[vec[x][i]])
		{
			par[vec[x][i]]=x;
			flg=flg|dfs(vec[x][i]);
		}

	if(arr[x]==-1)
		flg=1;

	pink[x]=flg;

	return flg;
}

void path(int x)
{
	int flg=0;
	visited[x]=1;
	ans.push_back(x);
	en[x]++;

	for (int i = 0; i < (int)vec[x].size(); ++i)
	{
		if(!visited[vec[x][i]])
			if(pink[vec[x][i]])
			{
				flg=1;
				path(vec[x][i]);
				ans.push_back(x);
				en[x]++;
			}
	}

	if(((x!=1)&&(en[x]%2)&&(arr[x]==1))||((x!=1)&&(en[x]%2==0)&&(arr[x]==-1)))
	{
		ans.push_back(par[x]);
		ans.push_back(x);
		en[x]++;
		en[par[x]]++;
	}

	if(((x==1)&&(flg)&&arr[1]==-1)||((x==1)&&(en[1]%2)&&(arr[1]==1)))
	{
		en[1]--;
		ans.pop_back();
	}
}

int main()
{
	cin>>n;

	for (int i = 1; i <= n; ++i)
		Sd(arr[i]);

	for (int i = 0; i < n-1; ++i)
	{
		Sd(a);Sd(b);
		vec[a].push_back(b);
		vec[b].push_back(a);
	}

	for (int i = 0; i < n; ++i)
		sort(vec[i+1].begin(), vec[i+1].end());

	par[1]=1;
	dfs(1);
	memset(visited,0,sizeof(visited));
	en[1]=-1;

	if(arr[1]==-1)
	{
		int flgg=0;
		for (int i = 0; i < (int)vec[1].size(); ++i)
			if(pink[vec[1][i]])
				flgg=1;

		if(flgg==0)
		{
			cout<<1<<" "<<vec[1][0]<<" "<<1<<" "<<vec[1][0]<<endl;
			return 0;
		}
	}
	path(1);

	for (int i = 0; i < (int)ans.size(); ++i)
		cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Sd(a) scanf("%d",&a)

int n,arr[200005],a,b,par[200005],pink[200005],visited[200005],en[200005];
vector<int> vec[200005],ans;
int dfs(int x)
{
	int flg=0;
	visited[x]=1;

	for (int i = 0; i < (int)vec[x].size(); ++i)
		if(!visited[vec[x][i]])
		{
			par[vec[x][i]]=x;
			flg=flg|dfs(vec[x][i]);
		}

	if(arr[x]==-1)
		flg=1;

	pink[x]=flg;

	return flg;
}

void path(int x)
{
	int flg=0;
	visited[x]=1;
	ans.push_back(x);
	en[x]++;

	for (int i = 0; i < (int)vec[x].size(); ++i)
	{
		if(!visited[vec[x][i]])
			if(pink[vec[x][i]])
			{
				flg=1;
				path(vec[x][i]);
				ans.push_back(x);
				en[x]++;
			}
	}

	if(((x!=1)&&(en[x]%2)&&(arr[x]==1))||((x!=1)&&(en[x]%2==0)&&(arr[x]==-1)))
	{
		ans.push_back(par[x]);
		ans.push_back(x);
		en[x]++;
		en[par[x]]++;
	}

	if(((x==1)&&(flg)&&arr[1]==-1)||((x==1)&&(en[1]%2)&&(arr[1]==1)))
	{
		en[1]--;
		ans.pop_back();
	}
}

int main()
{
	cin>>n;

	for (int i = 1; i <= n; ++i)
		Sd(arr[i]);

	for (int i = 0; i < n-1; ++i)
	{
		Sd(a);Sd(b);
		vec[a].push_back(b);
		vec[b].push_back(a);
	}

	par[1]=1;
	dfs(1);
	memset(visited,0,sizeof(visited));
	en[1]=-1;

	if(arr[1]==-1)
	{
		int flgg=0;
		for (int i = 0; i < (int)vec[1].size(); ++i)
			if(pink[vec[1][i]])
				flgg=1;

		if(flgg==0)
		{
			cout<<1<<" "<<vec[1][0]<<" "<<1<<" "<<vec[1][0]<<endl;
			return 0;
		}
	}
	path(1);

	for (int i = 0; i < (int)ans.size(); ++i)
		cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Sd(a) scanf("%d",&a)

int n,arr[200005],a,b,par[200005],pink[200005],visited[200005],en[200005];
vector<int> vec[200005],ans;
int dfs(int x)
{
	int flg=0;
	visited[x]=1;

	for (int i = 0; i < (int)vec[x].size(); ++i)
		if(!visited[vec[x][i]])
		{
			par[vec[x][i]]=x;
			flg=flg|dfs(vec[x][i]);
		}

	if(arr[x]==-1)
		flg=1;

	pink[x]=flg;

	return flg;
}

void path(int x)
{
	int flg=0;
	visited[x]=1;
	ans.push_back(x);
	en[x]++;

	for (int i = 0; i < (int)vec[x].size(); ++i)
	{
		if(!visited[vec[x][i]])
			if(pink[vec[x][i]])
			{
				flg=1;
				path(vec[x][i]);
				ans.push_back(x);
				en[x]++;
			}
	}

	if(((x!=1)&&(en[x]%2)&&(arr[x]==1))||((x!=1)&&(en[x]%2==0)&&(arr[x]==-1)))
	{
		ans.push_back(par[x]);
		ans.push_back(x);
		en[x]++;
		en[par[x]]++;
	}

	if(((x==1)&&(en[1]%2==0)&&arr[1]==-1)||((x==1)&&(en[1]%2)&&(arr[1]==1)))
	{
		en[1]--;
		ans.pop_back();
	}
}

int main()
{
	cin>>n;

	for (int i = 1; i <= n; ++i)
		Sd(arr[i]);

	for (int i = 0; i < n-1; ++i)
	{
		Sd(a);Sd(b);
		vec[a].push_back(b);
		vec[b].push_back(a);
	}

	for (int i = 0; i < n; ++i)
		sort(vec[i+1].begin(), vec[i+1].end());

	par[1]=1;
	dfs(1);
	memset(visited,0,sizeof(visited));
	en[1]=-1;

	if(arr[1]==-1)
	{
		int flgg=0;
		for (int i = 0; i < (int)vec[1].size(); ++i)
			if(pink[vec[1][i]])
				flgg=1;

		if(flgg==0)
		{
			cout<<1<<" "<<vec[1][0]<<" "<<1<<" "<<vec[1][0]<<endl;
			return 0;
		}
	}
	path(1);

	for (int i = 0; i < (int)ans.size(); ++i)
		cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef complex<double> point;

const double E = 1e-9, pi = 2*acos(0);
const ldouble PI = 3.1415926535897932384626433832795029L;

vector<bool> vis, has;
vector<vector<int> > adj;
vector<int> vet;
int rem;

void dfs(int u, int p) {
	has[u]=vis[u];
	for (int i=0; i<(int)adj[u].size(); i++) {
		int v=adj[u][i];
		if (v==p) continue;
		dfs(v, u);
		if (has[v]) has[u]=true;
	}
}

void visit(int x) {
	vis[x]=!vis[x];
	if (vis[x]) rem++;
	else rem--;
	vet.push_back(x);
}

void run(int u, int p) {
	for (int i=0; i<(int)adj[u].size(); i++) {
		int v=adj[u][i];
		if (v==p or !has[v]) continue;
		visit(v);
		run(v, u);
	}
	if (vis[u]) {
		if (p!=-1) {
			visit(p);
			visit(u);
		} else {
			int v=adj[u][0];
			visit(v);
			visit(u);
		}
	}
	if (rem) visit(p);
}

bool solve(int testNumber) {
	int n;
	if (scanf("%d", &n)==EOF) return false;
	vis.resize(n);
	has.resize(n);
	adj.assign(n, vector<int>());
	for (int i=0; i<n; i++) {
		int x;
		scanf("%d", &x);
		vis[i]=x==-1;
	}
	rem=count(vis.begin(), vis.end(), true);
	vet.assign(1, 0);
	for (int i=1; i<n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(0, -1);
	run(0, -1);
	for (int i=0; i<(int)vet.size(); i++) printf("%d ", vet[i]+1);
	printf("\n");
    return true;
}

void init() {

}

int main() {
    init();
    for (int i=1; solve(i); i++);
    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef complex<double> point;

const double E = 1e-9, pi = 2*acos(0);
const ldouble PI = 3.1415926535897932384626433832795029L;

vector<bool> vis, has;
vector<vector<int> > adj;
vector<int> vet;
int rem;

void dfs(int u, int p) {
	has[u]=vis[u];
	for (int i=0; i<(int)adj[u].size(); i++) {
		int v=adj[u][i];
		if (v==p) continue;
		dfs(v, u);
		if (has[v]) has[u]=true;
	}
}

void visit(int x) {
	vis[x]=!vis[x];
	if (vis[x]) rem++;
	else rem--;
	vet.push_back(x);
}

void run(int u, int p) {
	for (int i=0; i<(int)adj[u].size(); i++) {
		int v=adj[u][i];
		if (v==p or !has[v]) continue;
		visit(v);
		run(v, u);
	}
	if (vis[u]) {
		if (p==-1) {
			printf("BIRL!\n");
			exit(0);
		}
		visit(p);
		visit(u);
	}
	if (rem) visit(p);
}

bool solve(int testNumber) {
	int n;
	if (scanf("%d", &n)==EOF) return false;
	vis.resize(n);
	has.resize(n);
	adj.assign(n, vector<int>());
	for (int i=0; i<n; i++) {
		int x;
		scanf("%d", &x);
		vis[i]=x==-1;
	}
	rem=count(vis.begin(), vis.end(), true);
	vet.assign(1, 0);
	for (int i=1; i<n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(0, -1);
	run(0, -1);
	for (int i=0; i<(int)vet.size(); i++) printf("%d ", vet[i]+1);
	printf("\n");
    return true;
}

void init() {

}

int main() {
    init();
    for (int i=1; solve(i); i++);
    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef complex<double> point;

const double E = 1e-9, pi = 2*acos(0);
const ldouble PI = 3.1415926535897932384626433832795029L;

vector<bool> vis, has;
vector<vector<int> > adj;
vector<int> vet;
int rem;

void dfs(int u, int p) {
	has[u]=vis[u];
	for (int i=0; i<(int)adj[u].size(); i++) {
		int v=adj[u][i];
		if (v==p) continue;
		dfs(v, u);
		if (has[v]) has[u]=true;
	}
}

void visit(int x) {
	vis[x]=!vis[x];
	if (vis[x]) rem++;
	else rem--;
	vet.push_back(x);
}

void run(int u, int p) {
	for (int i=0; i<(int)adj[u].size(); i++) {
		int v=adj[u][i];
		if (v==p or !has[v]) continue;
		visit(v);
		run(v, u);
	}
	if (vis[u]) {
		if (p!=-1) {
			visit(p);
			visit(u);
		} else {
			int v=adj[u][0];
			visit(v);
			visit(u);
			visit(v);
		}
	}
	if (rem) {
		if (p==-1) {
			printf("BIRL!\n");
			exit(0);
		}
		visit(p);
	}
}

bool solve(int testNumber) {
	int n;
	if (scanf("%d", &n)==EOF) return false;
	vis.resize(n);
	has.resize(n);
	adj.assign(n, vector<int>());
	for (int i=0; i<n; i++) {
		int x;
		scanf("%d", &x);
		vis[i]=x==-1;
	}
	rem=count(vis.begin(), vis.end(), true);
	vet.assign(1, 0);
	for (int i=1; i<n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(0, -1);
	run(0, -1);
	for (int i=0; i<(int)vet.size(); i++) printf("%d ", vet[i]+1);
	printf("\n");
    return true;
}

void init() {

}

int main() {
    init();
    for (int i=1; solve(i); i++);
    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef complex<double> point;

const double E = 1e-9, pi = 2*acos(0);
const ldouble PI = 3.1415926535897932384626433832795029L;

vector<bool> vis, has;
vector<vector<int> > adj;
vector<int> vet;
int rem;

void dfs(int u, int p) {
	has[u]=vis[u];
	for (int i=0; i<(int)adj[u].size(); i++) {
		int v=adj[u][i];
		if (v==p) continue;
		dfs(v, u);
		if (has[v]) has[u]=true;
	}
}

void visit(int x) {
	vis[x]=!vis[x];
	if (vis[x]) rem++;
	else rem--;
	vet.push_back(x);
}

void run(int u, int p) {
	for (int i=0; i<(int)adj[u].size(); i++) {
		int v=adj[u][i];
		if (v==p or !has[v]) continue;
		visit(v);
		run(v, u);
	}
	if (vis[u]) {
		if (p!=-1) {
			visit(p);
			visit(u);
		} else {
			int v=adj[u][0];
			visit(v);
			visit(u);
		}
	}
	if (rem) {
		if (p==-1) {
			printf("BIRL!\n");
			exit(0);
		}
		visit(p);
	}
}

bool solve(int testNumber) {
	int n;
	if (scanf("%d", &n)==EOF) return false;
	vis.resize(n);
	has.resize(n);
	adj.assign(n, vector<int>());
	for (int i=0; i<n; i++) {
		int x;
		scanf("%d", &x);
		vis[i]=x==-1;
	}
	rem=count(vis.begin(), vis.end(), true);
	vet.assign(1, 0);
	for (int i=1; i<n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(0, -1);
	run(0, -1);
	for (int i=0; i<(int)vet.size(); i++) printf("%d ", vet[i]+1);
	printf("\n");
    return true;
}

void init() {

}

int main() {
    init();
    for (int i=1; solve(i); i++);
    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef complex<double> point;

const double E = 1e-9, pi = 2*acos(0);
const ldouble PI = 3.1415926535897932384626433832795029L;

vector<bool> vis, has;
vector<vector<int> > adj;
vector<int> vet;
int rem;

void dfs(int u, int p) {
	has[u]=vis[u];
	for (int i=0; i<(int)adj[u].size(); i++) {
		int v=adj[u][i];
		if (v==p) continue;
		dfs(v, u);
		if (has[v]) has[u]=true;
	}
}

void visit(int x) {
	vis[x]=!vis[x];
	if (vis[x]) rem++;
	else rem--;
	vet.push_back(x);
}

void run(int u, int p) {
	for (int i=0; i<(int)adj[u].size(); i++) {
		int v=adj[u][i];
		if (v==p or !has[v]) continue;
		visit(v);
		run(v, u);
	}
	if (vis[u]) {
		assert(p!=-1);
		visit(p);
		visit(u);
	}
	if (rem) visit(p);
}

bool solve(int testNumber) {
	int n;
	if (scanf("%d", &n)==EOF) return false;
	vis.resize(n);
	has.resize(n);
	adj.assign(n, vector<int>());
	for (int i=0; i<n; i++) {
		int x;
		scanf("%d", &x);
		vis[i]=x==-1;
	}
	rem=count(vis.begin(), vis.end(), true);
	vet.assign(1, 0);
	for (int i=1; i<n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(0, -1);
	run(0, -1);
	for (int i=0; i<(int)vet.size(); i++) printf("%d ", vet[i]+1);
	printf("\n");
    return true;
}

void init() {

}

int main() {
    init();
    for (int i=1; solve(i); i++);
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 1e6;
long long n, c, u, v, cnt, parent[MAXN];
vector <int> node[MAXN];
vector <int> path;
bool color[MAXN], mark[MAXN];

void dfs(int v){
    mark[v] = true;
    for (int i = 0; i < node[v].size(); i++){
        if (!mark[node[v][i]]){
            path.push_back(node[v][i]);
            parent[node[v][i]] = v;
            color[node[v][i]] = !color[node[v][i]];
            dfs(node[v][i]);
            path.push_back(v);
            color[v] = !color[v];
        }
    }
    if (color[v]){
        path.push_back(parent[v]);
        path.push_back(v);
        color[parent[v]] = !color[parent[v]];
        color[v] = !color[v];
    }
}

int main (){
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> c;
        if (c == 1){
            color[i] = 0;
            cnt++;
        }
        else
            color[i] = 1;
    }
    for (int i = 0; i < n - 1; i++){
        cin >> u >> v;
        node[v].push_back(u);
        node[u].push_back(v);
    }
    if(cnt == n)
        cout << 1 << '\n';
    else {
        mark[1] = true;
        color[1] = !color[1];
        for (int i = 0; i < node[1].size(); i++){
            path.push_back(1);
            parent[node[1][i]] = 1;
            dfs(node[1][i]);
            color[1] = !color[1];
        }
        if (color[1])
            path.push_back(1);
        for (int i = 0; i < path.size(); i++){
            cout << path[i] << ' ';
        }
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 1e6;
long long n, c, u, v, cnt, parent[MAXN];
vector <int> node[MAXN];
vector <int> path;
bool color[MAXN], mark[MAXN];

void dfs(int v){
    mark[v] = true;
    for (int i = 0; i < node[v].size(); i++){
        if (!mark[node[v][i]]){
            path.push_back(node[v][i]);
            parent[node[v][i]] = v;
            color[node[v][i]] = !color[node[v][i]];
            dfs(node[v][i]);
            path.push_back(v);
            color[v] = !color[v];
        }
    }
    if (color[v]){
        path.push_back(parent[v]);
        path.push_back(v);
        color[parent[v]] = !color[parent[v]];
        color[v] = !color[v];
    }
}

int main (){
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> c;
        if (c == 1){
            color[i] = 0;
            cnt++;
        }
        else
            color[i] = 1;
    }
    for (int i = 0; i < n - 1; i++){
        cin >> u >> v;
        node[v].push_back(u);
        node[u].push_back(v);
    }
    if(cnt == n)
        cout << 1 << '\n';
    else {
        path.push_back(1);
        dfs (1);
        if (color[1])
            path.push_back(1);
        for (int i = 0; i < path.size(); i++){
            cout << path[i] << ' ';
        }
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 1e6;
long long n, c, u, v, cnt, parent[MAXN];
vector <int> node[MAXN];
vector <int> path;
bool color[MAXN], mark[MAXN];

void dfs(int v){
    mark[v] = true;
    for (int i = 0; i < node[v].size(); i++){
        if (!mark[node[v][i]]){
            path.push_back(node[v][i]);
            parent[node[v][i]] = v;
            color[node[v][i]] = !color[node[v][i]];
            dfs(node[v][i]);
            path.push_back(v);
            color[v] = !color[v];
        }
    }
    if (color[v]){
        path.push_back(parent[v]);
        path.push_back(v);
        color[parent[v]] = !color[parent[v]];
        color[v] = !color[v];
    }
}

int main (){
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> c;
        if (c == 1){
            color[i] = 0;
            cnt++;
        }
        else
            color[i] = 1;
    }
    for (int i = 0; i < n - 1; i++){
        cin >> u >> v;
        node[v].push_back(u);
        node[u].push_back(v);
    }
    if(cnt == n)
        cout << 1 << '\n';
    else {
        mark[1] = true;
        for (int i = 0; i < node[1].size(); i++){
            path.push_back(1);
            dfs(node[1][i]);
            color[1] = !color[1];
        }
        if (color[1])
            path.push_back(1);
        for (int i = 0; i < path.size(); i++){
            cout << path[i] << ' ';
        }
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 1e6;
long long n, c, u, v, cnt, parent[MAXN];
vector <int> node[MAXN];
vector <int> path;
bool color[MAXN], mark[MAXN];

void dfs(int v){
    mark[v] = true;
    for (int i = 0; i < node[v].size(); i++){
        if (!mark[node[v][i]]){
            path.push_back(node[v][i]);
            parent[node[v][i]] = v;
            color[node[v][i]] = !color[node[v][i]];
            dfs(node[v][i]);
            path.push_back(v);
            color[v] = !color[v];
        }
    }
    if (color[v]){
        path.push_back(parent[v]);
        path.push_back(v);
        color[parent[v]] = !color[parent[v]];
        color[v] = !color[v];
    }
}

int main (){
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> c;
        if (c == 1){
            color[i] = 0;
            cnt++;
        }
        else
            color[i] = 1;
    }
    for (int i = 0; i < n - 1; i++){
        cin >> u >> v;
        node[v].push_back(u);
        node[u].push_back(v);
    }
    if(cnt == n)
        cout << 1 << '\n';
    else {
        path.push_back(1);
        dfs (1);
        path.pop_back();
        if (color[1])
            path.push_back(1);
        for (int i = 0; i < path.size(); i++){
            cout << path[i] << ' ';
        }
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 1e6;
long long n, c, u, v, cnt, parent[MAXN];
vector <int> node[MAXN];
vector <int> path;
bool color[MAXN], mark[MAXN];

void dfs(int v){
    mark[v] = true;
    for (int i = 0; i < node[v].size(); i++){
        if (!mark[node[v][i]]){
            path.push_back(node[v][i]);
            parent[node[v][i]] = v;
            color[node[v][i]] = !color[node[v][i]];
            dfs(node[v][i]);
            path.push_back(v);
            color[v] = !color[v];
        }
    }
    if (color[v]){
        path.push_back(parent[v]);
        path.push_back(v);
        color[parent[v]] = !color[parent[v]];
        color[v] = !color[v];
    }
}

int main (){
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> c;
        if (c == 1){
            color[i] = 0;
            cnt++;
        }
        else
            color[i] = 1;
    }
    for (int i = 0; i < n - 1; i++){
        cin >> u >> v;
        node[v].push_back(u);
        node[u].push_back(v);
    }
    if(cnt == n)
        cout << 1 << '\n';
    else {
        mark[1] = true;
        for (int i = 0; i < node[1].size(); i++){
            path.push_back(1);
            path.push_back(node[1][i]);
            color[node[1][i]] = !color[node[1][i]];
            parent[node[1][i]] = 1;
            dfs(node[1][i]);
            color[1] = !color[1];
        }
        if (color[1])
            path.push_back(1);
        for (int i = 0; i < path.size(); i++){
            cout << path[i] << ' ';
        }
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 1e6;
long long n, c, u, v, cnt, parent[MAXN];
vector <int> node[MAXN];
vector <int> path;
bool color[MAXN], mark[MAXN];

void dfs(int v){
    mark[v] = true;
    for (int i = 0; i < node[v].size(); i++){
        if (!mark[node[v][i]]){
            path.push_back(node[v][i]);
            parent[node[v][i]] = v;
            color[node[v][i]] = !color[node[v][i]];
            dfs(node[v][i]);
            path.push_back(v);
            color[v] = !color[v];
        }
    }
    if (color[v]){
        path.push_back(parent[v]);
        path.push_back(v);
        color[parent[v]] = !color[parent[v]];
        color[v] = !color[v];
    }
}

int main (){
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> c;
        if (c == 1){
            color[i] = 0;
            cnt++;
        }
        else
            color[i] = 1;
    }
    for (int i = 0; i < n - 1; i++){
        cin >> u >> v;
        node[v].push_back(u);
        node[u].push_back(v);
    }
    if(cnt == n)
        cout << 1 << '\n';
    else {
        mark[1] = true;
        color[1] = !color[1];
        for (int i = 0; i < node[1].size(); i++){
            path.push_back(1);
            path.push_back(node[1][i]);
            color[node[1][i]] = !color[node[1][i]];
            parent[node[1][i]] = 1;
            dfs(node[1][i]);
            color[1] = !color[1];
        }
        if (color[1])
            path.push_back(1);
        for (int i = 0; i < path.size(); i++){
            cout << path[i] << ' ';
        }
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 1e6;
long long n, c, u, v, cnt;
vector <int> node[MAXN];
vector <int> path;
bool color[MAXN], mark[MAXN];

void dfs(int v){
    mark[v] = true;
    for (int i = 0; i < node[v].size(); i++){
        if (!mark[node[v][i]]){
            path.push_back(node[v][i]);
            dfs(node[v][i]);
            path.push_back(v);
            color[node[v][i]] = !color[node[v][i]];
            color[v] = !color[v];
        }
    }
}

int main (){
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> c;
        if (c == 1){
            color[i] = 0;
            cnt++;
        }
        else
            color[i] = 1;
    }
    for (int i = 0; i < n - 1; i++){
        cin >> u >> v;
        node[v].push_back(u);
        node[u].push_back(v);
    }
    if(cnt == n)
        cout << 1 << '\n';
    else {
        dfs (1);
        path.pop_back();
        for (int i = path.size() - 1; i > 0; i--){
            if (path[i]){
                path.push_back(path[i - 1]);
                path.push_back(path[i]);
                path.push_back(path[i - 1]);
                color[path[i]] = !color[path[i]];
            }
            else {
                path.push_back(path[i - 1]);
                color[path[i - 1]] = !color[path[i - 1]];
            }
        }
        if (color[1])
            path.push_back(1);
        for (int i = 0; i < path.size(); i++){
            cout << path[i] << ' ';
        }
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 1e6;
long long n, c, u, v, cnt;
vector <int> node[MAXN];
vector <int> path;
bool color[MAXN], mark[MAXN];

void dfs(int v){
    mark[v] = true;
    for (int i = 0; i < node[v].size(); i++){
        if (!mark[node[v][i]]){
            path.push_back(node[v][i]);
            dfs(node[v][i]);
            path.push_back(v);
            color[node[v][i]] = !color[node[v][i]];
            color[v] = !color[v];
        }
    }
}

int main (){
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> c;
        if (c == 1){
            color[i] = 0;
            cnt++;
        }
        else
            color[i] = 1;
    }
    for (int i = 0; i < n - 1; i++){
        cin >> u >> v;
        node[v].push_back(u);
        node[u].push_back(v);
    }
    if(cnt == n)
        cout << 1 << '\n';
    else {
        path.push_back(1);
        dfs (1);
        path.pop_back();
        for (int i = path.size() - 1; i > 0; i--){
            if (path[i]){
                path.push_back(path[i - 1]);
                path.push_back(path[i]);
                path.push_back(path[i - 1]);
                color[path[i]] = !color[path[i]];
            }
            else {
                path.push_back(path[i - 1]);
                color[path[i - 1]] = !color[path[i - 1]];
            }
        }
        if (color[1])
            path.push_back(1);
        for (int i = 0; i < path.size(); i++){
            cout << path[i] << ' ';
        }
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 1e6;
long long n, c, u, v;
vector <int> node[MAXN];
vector <int> path;
bool color[MAXN], mark[MAXN];

void dfs(int v){
    mark[v] = true;
    for (int i = 0; i < node[v].size(); i++){
        if (!mark[node[v][i]]){
            path.push_back(node[v][i]);
            dfs(node[v][i]);
            path.push_back(v);
            color[node[v][i]] = !color[node[v][i]];
            color[v] = !color[v];
        }
    }
}

int main (){
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> c;
        if (c == 1){
            color[i] = 0;
            cnt++;
        }
        else
            color[i] = 1;
    }
    for (int i = 0; i < n - 1; i++){
        cin >> u >> v;
        node[v].push_back(u);
        node[u].push_back(v);
    }
    if(cnt == n)
        cout << 1 << '\n';
    else {
        dfs (1);
        path.pop_back();
        for (int i = path.size() - 1; i > 0; i--){
            if (path[i]){
                path.push_back(path[i - 1]);
                path.push_back(path[i]);
                path.push_back(path[i - 1]);
                color[path[i]] = !color[path[i]];
            }
            else {
                path.push_back(path[i - 1]);
                color[path[i - 1]] = !color[path[i - 1]];
            }
        }
        if (color[1])
            path.push_back(1);
        for (int i = 0; i < path.size(); i++){
            cout << path[i] << ' ';
        }
    }
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <utility>
#include <iterator>
#include <sstream>
#include <fstream>
#include <functional>
#include <ctime>
#include <cassert>

using namespace std;

#define SyncFalse ios::sync_with_stdio(0); cin.tie(0)
#define MEM(a, v) memset(a, v, sizeof(a))
#define CLRV(a, sz, v) a.clear(); a.resize(sz, v)
#define CLR(a, sz) a.clear(); a.resize(sz)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.end(), a.begin()
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define SZ(a) (int)a.size()
#define LNG(a) (int)a.length()
#define LPI 3.141592653589793238462643383279502884L
#define SI(n) scanf("%d", &n)
#define SL(n) scanf("%lld", &n)
#define SD(n) scanf("%f", &n)
#define SLD(n) scanf("%lf", &n)
#define SC(n) scanf("%c", &n)
#define SS(n) scanf("%s", n)
#define FOR(i, x, j, y) for (int i = x; i < j; i += y)
#define RFOR(i, x, j, y) for (int i = x - 1; i >= j; i -= y)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define FOREACH(it, a) for (auto it = a.begin(); it != a.end(); it++)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<ld> VLD;
typedef vector<double> VD;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef vector<PII> VPII;
typedef vector<VPII> VVPII;

const double PI = acos(-1.0);
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int MOD = (int) 1e9 + 7;

//------------------------------------------------------------------------

int n;
VI c, sub;
VVI g;
VI sol;

int dfs1(int u, int p) {
    sub[u] = (c[u] == -1) ? 1 : 0;
    REP(i, SZ(g[u])) {
        int v = g[u][i];
        if (v != p) {
            sub[u] += dfs1(v, u);
        }
    }
    return sub[u];
}

int dfs(int u, int p) {
    int ret = c[u];
    if (c[u] == -1) {
        c[u] = 1;
    } else {
        c[u] = -1;
    }
    if (u + 1 != sol.back()) {
        sol.PB(u + 1);
    }
    REP(i, SZ(g[u])) {
        int v = g[u][i];
        if (v != p && sub[v] != 0) {
            ret += dfs(v, u);
            ret += c[u];
            if (c[u] == -1) {
                c[u] = 1;
            } else {
                c[u] = -1;
            }
            sol.PB(u + 1);
        }
    }
    sub[u] += ret;
    return ret;
}

int main() {
    SI(n);
    c.resize(n);
    sub.resize(n, 0);
    g.resize(n);
    REP(i, n) {
        SI(c[i]);
    }
    REP(i, n - 1) {
        int a, b;
        SI(a), SI(b);
        a--, b--;
        g[a].PB(b);
        g[b].PB(a);
    }
    dfs1(0, -1);
    sol.PB(1);
    while (sub[0] != 0) {
        dfs(0, -1);
    }
    REP(i, SZ(sol)) {
        printf("%d ", sol[i]);
    }
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <utility>
#include <iterator>
#include <sstream>
#include <fstream>
#include <functional>
#include <ctime>
#include <cassert>
#include <limits>

using namespace std;

#define SyncFalse ios::sync_with_stdio(0); cin.tie(0)
#define MEM(a, v) memset(a, v, sizeof(a))
#define CLRV(a, sz, v) a.clear(); a.resize(sz, v)
#define CLR(a, sz) a.clear(); a.resize(sz)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.end(), a.begin()
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define SZ(a) (int)a.size()
#define LNG(a) (int)a.length()
#define LPI 3.141592653589793238462643383279502884L
#define SI(n) scanf("%d", &n)
#define SL(n) scanf("%lld", &n)
#define SD(n) scanf("%f", &n)
#define SLD(n) scanf("%lf", &n)
#define SC(n) scanf(" %c", &n)
#define SS(n) scanf(" %s", n)
#define FOR(i, x, j, y) for (int i = x; i < j; i += y)
#define RFOR(i, x, j, y) for (int i = x - 1; i >= j; i -= y)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define FOREACH(it, a) for (auto it = a.begin(); it != a.end(); it++)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<ld> VLD;
typedef vector<double> VD;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef vector<PII> VPII;
typedef vector<VPII> VVPII;

const double PI = acos(-1.0);
const double EPS = numeric_limits<double>::epsilon();
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int MOD = (int) 1e9 + 7;

//------------------------------------------------------------------------

int n;
VI c, sub;
VVI g;
VI sol;

void dfs1(int u, int p) {
    sub[u] = 0;
    sub[u] = !c[u];
    REP(i, SZ(g[u])) {
        int v = g[u][i];
        if (v != p) {
            dfs1(v, u);
            sub[u] += sub[v];
        }
    }
}

void dfs(int u, int p) {
    sol.PB(u + 1);
    c[u] = !c[u];
    while (1) {
        sub[u] = 0;
        REP(i, SZ(g[u])) {
            int v = g[u][i];
            if (v != p && sub[v]) {
                dfs(v, u);
                sub[u] += sub[v];
                c[u] = !c[u];
                sol.PB(u + 1);
            }
        }
        if (!sub[u]) {
            break;
        }
    }
    sub[u] = !c[u];
}

int main() {
    SI(n);
    c.resize(n);
    sub.resize(n, 0);
    g.resize(n);
    REP(i, n) {
        SI(c[i]);
        if (c[i] == -1) {
            c[i] = 0;
        }
    }
    REP(i, n - 1) {
        int a, b;
        SI(a), SI(b);
        a--, b--;
        g[a].PB(b);
        g[b].PB(a);
    }
    dfs1(0, -1);
    c[0] = !c[0];
    dfs(0, -1);
    if (!c[0]) {
        sol.PB(g[0][0] + 1);
        sol.PB(1);
        sol.PB(g[0][0] + 1);
    }
    REP(i, SZ(sol)) {
        printf("%d ", sol[i]);
    }
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <utility>
#include <iterator>
#include <sstream>
#include <fstream>
#include <functional>
#include <ctime>
#include <cassert>

using namespace std;

#define SyncFalse ios::sync_with_stdio(0); cin.tie(0)
#define MEM(a, v) memset(a, v, sizeof(a))
#define CLRV(a, sz, v) a.clear(); a.resize(sz, v)
#define CLR(a, sz) a.clear(); a.resize(sz)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.end(), a.begin()
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define SZ(a) (int)a.size()
#define LNG(a) (int)a.length()
#define LPI 3.141592653589793238462643383279502884L
#define SI(n) scanf("%d", &n)
#define SL(n) scanf("%lld", &n)
#define SD(n) scanf("%f", &n)
#define SLD(n) scanf("%lf", &n)
#define SC(n) scanf("%c", &n)
#define SS(n) scanf("%s", n)
#define FOR(i, x, j, y) for (int i = x; i < j; i += y)
#define RFOR(i, x, j, y) for (int i = x - 1; i >= j; i -= y)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define FOREACH(it, a) for (auto it = a.begin(); it != a.end(); it++)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<ld> VLD;
typedef vector<double> VD;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef vector<PII> VPII;
typedef vector<VPII> VVPII;

const double PI = acos(-1.0);
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int MOD = (int) 1e9 + 7;

//------------------------------------------------------------------------

int n;
VI c, sub;
VVI g;
VI sol;

int dfs1(int u, int p) {
    sub[u] = (c[u] == -1) ? 1 : 0;
    REP(i, SZ(g[u])) {
        int v = g[u][i];
        if (v != p) {
            sub[u] += dfs1(v, u);
        }
    }
    return sub[u];
}

int dfs(int u, int p) {
    int ret = 0;
    if (u + 1 != sol.back()) {
        ret = c[u];
        if (c[u] == -1) {
            c[u] = 1;
        } else {
            c[u] = -1;
        }
        sol.PB(u + 1);
    }
    while ((c[u] == 1 && sub[u] + ret != 0) || (c[u] == -1 && sub[u] + ret != 1)) {
        REP(i, SZ(g[u])) {
            int v = g[u][i];
            if (v != p && sub[v] != 0) {
                ret += dfs(v, u);
                if (sub[u] + ret == 0) {
                    break;
                }
                ret += c[u];
                if (c[u] == -1) {
                    c[u] = 1;
                } else {
                    c[u] = -1;
                }
                sol.PB(u + 1);
            }
        }
    }
    sub[u] += ret;
    return ret;
}

int main() {
    SI(n);
    c.resize(n);
    sub.resize(n, 0);
    g.resize(n);
    REP(i, n) {
        SI(c[i]);
    }
    REP(i, n - 1) {
        int a, b;
        SI(a), SI(b);
        a--, b--;
        g[a].PB(b);
        g[b].PB(a);
    }
    dfs1(0, -1);
    sol.PB(1);
    dfs(0, -1);
    REP(i, SZ(sol)) {
        printf("%d ", sol[i]);
    }
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <utility>
#include <iterator>
#include <sstream>
#include <fstream>
#include <functional>
#include <ctime>
#include <cassert>

using namespace std;

#define SyncFalse ios::sync_with_stdio(0); cin.tie(0)
#define MEM(a, v) memset(a, v, sizeof(a))
#define CLRV(a, sz, v) a.clear(); a.resize(sz, v)
#define CLR(a, sz) a.clear(); a.resize(sz)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.end(), a.begin()
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define SZ(a) (int)a.size()
#define LNG(a) (int)a.length()
#define LPI 3.141592653589793238462643383279502884L
#define SI(n) scanf("%d", &n)
#define SL(n) scanf("%lld", &n)
#define SD(n) scanf("%f", &n)
#define SLD(n) scanf("%lf", &n)
#define SC(n) scanf("%c", &n)
#define SS(n) scanf("%s", n)
#define FOR(i, x, j, y) for (int i = x; i < j; i += y)
#define RFOR(i, x, j, y) for (int i = x - 1; i >= j; i -= y)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define FOREACH(it, a) for (auto it = a.begin(); it != a.end(); it++)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<ld> VLD;
typedef vector<double> VD;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef vector<PII> VPII;
typedef vector<VPII> VVPII;

const double PI = acos(-1.0);
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int MOD = (int) 1e9 + 7;

//------------------------------------------------------------------------

int n;
VI c, sub;
VVI g;
VI sol;

int dfs1(int u, int p) {
    sub[u] = (c[u] == -1) ? 1 : 0;
    REP(i, SZ(g[u])) {
        int v = g[u][i];
        if (v != p) {
            sub[u] += dfs1(v, u);
        }
    }
    return sub[u];
}

int dfs(int u, int p) {
    int ret = c[u];
    if (c[u] == -1) {
        c[u] = 1;
    } else {
        c[u] = -1;
    }
        sol.PB(u + 1);
    REP(i, SZ(g[u])) {
        int v = g[u][i];
        if (v != p && sub[v] != 0) {
            ret += dfs(v, u);
            ret += c[u];
            if (c[u] == -1) {
                c[u] = 1;
            } else {
                c[u] = -1;
            }
            sol.PB(u + 1);
        }
    }
    sub[u] += ret;
    return ret;
}

int main() {
    SI(n);
    c.resize(n);
    sub.resize(n, 0);
    g.resize(n);
    REP(i, n) {
        SI(c[i]);
    }
    REP(i, n - 1) {
        int a, b;
        SI(a), SI(b);
        a--, b--;
        g[a].PB(b);
        g[b].PB(a);
    }
    dfs1(0, -1);
    while (sub[0] != 0) {
        dfs(0, -1);
    }
    REP(i, SZ(sol)) {
        printf("%d ", sol[i]);
    }
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <utility>
#include <iterator>
#include <sstream>
#include <fstream>
#include <functional>
#include <ctime>
#include <cassert>

using namespace std;

#define SyncFalse ios::sync_with_stdio(0); cin.tie(0)
#define MEM(a, v) memset(a, v, sizeof(a))
#define CLRV(a, sz, v) a.clear(); a.resize(sz, v)
#define CLR(a, sz) a.clear(); a.resize(sz)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.end(), a.begin()
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define SZ(a) (int)a.size()
#define LNG(a) (int)a.length()
#define LPI 3.141592653589793238462643383279502884L
#define SI(n) scanf("%d", &n)
#define SL(n) scanf("%lld", &n)
#define SD(n) scanf("%f", &n)
#define SLD(n) scanf("%lf", &n)
#define SC(n) scanf("%c", &n)
#define SS(n) scanf("%s", n)
#define FOR(i, x, j, y) for (int i = x; i < j; i += y)
#define RFOR(i, x, j, y) for (int i = x - 1; i >= j; i -= y)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define FOREACH(it, a) for (auto it = a.begin(); it != a.end(); it++)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<ld> VLD;
typedef vector<double> VD;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef vector<PII> VPII;
typedef vector<VPII> VVPII;

const double PI = acos(-1.0);
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int MOD = (int) 1e9 + 7;

//------------------------------------------------------------------------

int n;
VI c, sub;
VVI g;
VI sol;

int dfs1(int u, int p) {
    sub[u] = (c[u] == -1) ? 1 : 0;
    REP(i, SZ(g[u])) {
        int v = g[u][i];
        if (v != p) {
            sub[u] += dfs1(v, u);
        }
    }
    return sub[u];
}

int dfs(int u, int p) {
    int ret = 0;
    if (u + 1 != sol.back()) {
        ret = c[u];
        if (c[u] == -1) {
            c[u] = 1;
        } else {
            c[u] = -1;
        }
        sol.PB(u + 1);
    }
    REP(i, SZ(g[u])) {
        int v = g[u][i];
        if (v != p && sub[v] != 0) {
            ret += dfs(v, u);
            if (sub[u] + ret == 0) {
                break;
            }
            ret += c[u];
            if (c[u] == -1) {
                c[u] = 1;
            } else {
                c[u] = -1;
            }
            sol.PB(u + 1);
        }
    }
    sub[u] += ret;
    return ret;
}

int main() {
    SI(n);
    c.resize(n);
    sub.resize(n, 0);
    g.resize(n);
    REP(i, n) {
        SI(c[i]);
    }
    REP(i, n - 1) {
        int a, b;
        SI(a), SI(b);
        a--, b--;
        g[a].PB(b);
        g[b].PB(a);
    }
    dfs1(0, -1);
    sol.PB(1);
    while (sub[0] != 0) {
        dfs(0, -1);
    }
    REP(i, SZ(sol)) {
        printf("%d ", sol[i]);
    }
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <utility>
#include <iterator>
#include <sstream>
#include <fstream>
#include <functional>
#include <ctime>
#include <cassert>

using namespace std;

#define SyncFalse ios::sync_with_stdio(0); cin.tie(0)
#define MEM(a, v) memset(a, v, sizeof(a))
#define CLRV(a, sz, v) a.clear(); a.resize(sz, v)
#define CLR(a, sz) a.clear(); a.resize(sz)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.end(), a.begin()
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define SZ(a) (int)a.size()
#define LNG(a) (int)a.length()
#define LPI 3.141592653589793238462643383279502884L
#define SI(n) scanf("%d", &n)
#define SL(n) scanf("%lld", &n)
#define SD(n) scanf("%f", &n)
#define SLD(n) scanf("%lf", &n)
#define SC(n) scanf("%c", &n)
#define SS(n) scanf("%s", n)
#define FOR(i, x, j, y) for (int i = x; i < j; i += y)
#define RFOR(i, x, j, y) for (int i = x - 1; i >= j; i -= y)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define FOREACH(it, a) for (auto it = a.begin(); it != a.end(); it++)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<ld> VLD;
typedef vector<double> VD;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef vector<PII> VPII;
typedef vector<VPII> VVPII;

const double PI = acos(-1.0);
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int MOD = (int) 1e9 + 7;

//------------------------------------------------------------------------

int n;
VI c, sub;
VVI g;
VI sol;

int dfs1(int u, int p) {
    sub[u] = (c[u] == -1) ? 1 : 0;
    REP(i, SZ(g[u])) {
        int v = g[u][i];
        if (v != p) {
            sub[u] += dfs1(v, u);
        }
    }
    return sub[u];
}

int dfs(int u, int p) {
    int ret = 0;
    if (u + 1 != sol.back()) {
        ret = c[u];
        if (c[u] == -1) {
            c[u] = 1;
        } else {
            c[u] = -1;
        }
        sol.PB(u + 1);
    }
    REP(i, SZ(g[u])) {
        int v = g[u][i];
        if (v != p && sub[v] != 0) {
            ret += dfs(v, u);
            if (sub[0] + ret == 0) {
                break;
            }
            ret += c[u];
            if (c[u] == -1) {
                c[u] = 1;
            } else {
                c[u] = -1;
            }
            sol.PB(u + 1);
        }
    }
    sub[u] += ret;
    return ret;
}

int main() {
    SI(n);
    c.resize(n);
    sub.resize(n, 0);
    g.resize(n);
    REP(i, n) {
        SI(c[i]);
    }
    REP(i, n - 1) {
        int a, b;
        SI(a), SI(b);
        a--, b--;
        g[a].PB(b);
        g[b].PB(a);
    }
    dfs1(0, -1);
    sol.PB(1);
    while (sub[0] != 0) {
        dfs(0, -1);
    }
    REP(i, SZ(sol)) {
        printf("%d ", sol[i]);
    }
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <utility>
#include <iterator>
#include <sstream>
#include <fstream>
#include <functional>
#include <ctime>
#include <cassert>

using namespace std;

#define SyncFalse ios::sync_with_stdio(0); cin.tie(0)
#define MEM(a, v) memset(a, v, sizeof(a))
#define CLRV(a, sz, v) a.clear(); a.resize(sz, v)
#define CLR(a, sz) a.clear(); a.resize(sz)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.end(), a.begin()
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define SZ(a) (int)a.size()
#define LNG(a) (int)a.length()
#define LPI 3.141592653589793238462643383279502884L
#define SI(n) scanf("%d", &n)
#define SL(n) scanf("%lld", &n)
#define SD(n) scanf("%f", &n)
#define SLD(n) scanf("%lf", &n)
#define SC(n) scanf("%c", &n)
#define SS(n) scanf("%s", n)
#define FOR(i, x, j, y) for (int i = x; i < j; i += y)
#define RFOR(i, x, j, y) for (int i = x - 1; i >= j; i -= y)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define FOREACH(it, a) for (auto it = a.begin(); it != a.end(); it++)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<ld> VLD;
typedef vector<double> VD;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef vector<PII> VPII;
typedef vector<VPII> VVPII;

const double PI = acos(-1.0);
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int MOD = (int) 1e9 + 7;

//------------------------------------------------------------------------

int n;
VI c, sub;
VVI g;
VI sol;

int dfs1(int u, int p) {
    sub[u] = (c[u] == -1) ? 1 : 0;
    REP(i, SZ(g[u])) {
        int v = g[u][i];
        if (v != p) {
            sub[u] += dfs1(v, u);
        }
    }
    return sub[u];
}

int dfs(int u, int p) {
    int ret = 0;
        ret = c[u];
        if (c[u] == -1) {
            c[u] = 1;
        } else {
            c[u] = -1;
        }
        sol.PB(u + 1);
    while ((c[u] == 1 && sub[u] + ret != 0) || (c[u] == -1 && sub[u] + ret != 1)) {
        REP(i, SZ(g[u])) {
            int v = g[u][i];
            if (v != p && sub[v] != 0) {
                ret += dfs(v, u);
                if (sub[0] + ret == 0) {
                    break;
                }
                ret += c[u];
                if (c[u] == -1) {
                    c[u] = 1;
                } else {
                    c[u] = -1;
                }
                sol.PB(u + 1);
            }
        }
    }
    sub[u] += ret;
    return ret;
}

int main() {
    SI(n);
    c.resize(n);
    sub.resize(n, 0);
    g.resize(n);
    REP(i, n) {
        SI(c[i]);
    }
    REP(i, n - 1) {
        int a, b;
        SI(a), SI(b);
        a--, b--;
        g[a].PB(b);
        g[b].PB(a);
    }
    dfs1(0, -1);
    dfs(0, -1);
    REP(i, SZ(sol)) {
        printf("%d ", sol[i]);
    }
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <utility>
#include <iterator>
#include <sstream>
#include <fstream>
#include <functional>
#include <ctime>
#include <cassert>

using namespace std;

#define SyncFalse ios::sync_with_stdio(0); cin.tie(0)
#define MEM(a, v) memset(a, v, sizeof(a))
#define CLRV(a, sz, v) a.clear(); a.resize(sz, v)
#define CLR(a, sz) a.clear(); a.resize(sz)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.end(), a.begin()
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define SZ(a) (int)a.size()
#define LNG(a) (int)a.length()
#define LPI 3.141592653589793238462643383279502884L
#define SI(n) scanf("%d", &n)
#define SL(n) scanf("%lld", &n)
#define SD(n) scanf("%f", &n)
#define SLD(n) scanf("%lf", &n)
#define SC(n) scanf("%c", &n)
#define SS(n) scanf("%s", n)
#define FOR(i, x, j, y) for (int i = x; i < j; i += y)
#define RFOR(i, x, j, y) for (int i = x - 1; i >= j; i -= y)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define FOREACH(it, a) for (auto it = a.begin(); it != a.end(); it++)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<ld> VLD;
typedef vector<double> VD;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef vector<PII> VPII;
typedef vector<VPII> VVPII;

const double PI = acos(-1.0);
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int MOD = (int) 1e9 + 7;

//------------------------------------------------------------------------

int n;
VI c, sub;
VVI g;
VI sol;

int dfs1(int u, int p) {
    sub[u] = (c[u] == -1) ? 1 : 0;
    REP(i, SZ(g[u])) {
        int v = g[u][i];
        if (v != p) {
            sub[u] += dfs1(v, u);
        }
    }
    return sub[u];
}

int dfs(int u, int p) {
    int ret = 0;
    if (u + 1 != sol.back()) {
        ret = c[u];
        if (c[u] == -1) {
            c[u] = 1;
        } else {
            c[u] = -1;
        }
        sol.PB(u + 1);
    }
    while ((c[u] == 1 && sub[u] + ret != 0) || (c[u] == -1 && sub[u] + ret != 1)) {
        REP(i, SZ(g[u])) {
            int v = g[u][i];
            if (v != p && sub[v] != 0) {
                ret += dfs(v, u);
                if (sub[0] + ret == 0) {
                    break;
                }
                ret += c[u];
                if (c[u] == -1) {
                    c[u] = 1;
                } else {
                    c[u] = -1;
                }
                sol.PB(u + 1);
            }
        }
    }
    sub[u] += ret;
    return ret;
}

int main() {
    SI(n);
    c.resize(n);
    sub.resize(n, 0);
    g.resize(n);
    REP(i, n) {
        SI(c[i]);
    }
    REP(i, n - 1) {
        int a, b;
        SI(a), SI(b);
        a--, b--;
        g[a].PB(b);
        g[b].PB(a);
    }
    dfs1(0, -1);
    sol.PB(1);
    dfs(0, -1);
    REP(i, SZ(sol)) {
        printf("%d ", sol[i]);
    }
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <utility>
#include <iterator>
#include <sstream>
#include <fstream>
#include <functional>
#include <ctime>
#include <cassert>
#include <limits>

using namespace std;

#define SyncFalse ios::sync_with_stdio(0); cin.tie(0)
#define MEM(a, v) memset(a, v, sizeof(a))
#define CLRV(a, sz, v) a.clear(); a.resize(sz, v)
#define CLR(a, sz) a.clear(); a.resize(sz)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.end(), a.begin()
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define SZ(a) (int)a.size()
#define LNG(a) (int)a.length()
#define LPI 3.141592653589793238462643383279502884L
#define SI(n) scanf("%d", &n)
#define SL(n) scanf("%lld", &n)
#define SD(n) scanf("%f", &n)
#define SLD(n) scanf("%lf", &n)
#define SC(n) scanf(" %c", &n)
#define SS(n) scanf(" %s", n)
#define FOR(i, x, j, y) for (int i = x; i < j; i += y)
#define RFOR(i, x, j, y) for (int i = x - 1; i >= j; i -= y)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define FOREACH(it, a) for (auto it = a.begin(); it != a.end(); it++)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<ld> VLD;
typedef vector<double> VD;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef vector<PII> VPII;
typedef vector<VPII> VVPII;

const double PI = acos(-1.0);
const double EPS = numeric_limits<double>::epsilon();
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int MOD = (int) 1e9 + 7;

//------------------------------------------------------------------------

int n;
VI c, sub;
VVI g;
VI sol;

void dfs1(int u, int p) {
    sub[u] = 0;
    sub[u] = !c[u];
    REP(i, SZ(g[u])) {
        int v = g[u][i];
        if (v != p) {
            dfs1(v, u);
            sub[u] += sub[v];
        }
    }
}

void dfs(int u, int p) {
    sol.PB(u + 1);
    c[u] = !c[u];
    while(1) {
        sub[u] = 0;
        REP(i, SZ(g[u])) {
            int v = g[u][i];
            if (v != p && sub[v]) {
                dfs(v, u);
                sub[u] += sub[v];
                c[u] = !c[u];
                sol.PB(u + 1);
            }
        }
        if (!sub[u]) {
            break;
        }
    }
}

int main() {
    SI(n);
    c.resize(n);
    sub.resize(n, 0);
    g.resize(n);
    REP(i, n) {
        SI(c[i]);
        if (c[i] == -1) {
            c[i] = 0;
        }
    }
    REP(i, n - 1) {
        int a, b;
        SI(a), SI(b);
        a--, b--;
        g[a].PB(b);
        g[b].PB(a);
    }
    dfs1(0, -1);
    while (1) {
        dfs(0, -1);
        c[0] = !c[0];
        if (sub[0] == 0) {
            break;
        }
    }
    REP(i, SZ(sol)) {
        printf("%d ", sol[i]);
    }
    printf("\n");
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <utility>
#include <iterator>
#include <sstream>
#include <fstream>
#include <functional>
#include <ctime>
#include <cassert>

using namespace std;

#define SyncFalse ios::sync_with_stdio(0); cin.tie(0)
#define MEM(a, v) memset(a, v, sizeof(a))
#define CLRV(a, sz, v) a.clear(); a.resize(sz, v)
#define CLR(a, sz) a.clear(); a.resize(sz)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.end(), a.begin()
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define SZ(a) (int)a.size()
#define LNG(a) (int)a.length()
#define LPI 3.141592653589793238462643383279502884L
#define SI(n) scanf("%d", &n)
#define SL(n) scanf("%lld", &n)
#define SD(n) scanf("%f", &n)
#define SLD(n) scanf("%lf", &n)
#define SC(n) scanf("%c", &n)
#define SS(n) scanf("%s", n)
#define FOR(i, x, j, y) for (int i = x; i < j; i += y)
#define RFOR(i, x, j, y) for (int i = x - 1; i >= j; i -= y)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define FOREACH(it, a) for (auto it = a.begin(); it != a.end(); it++)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<ld> VLD;
typedef vector<double> VD;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef vector<PII> VPII;
typedef vector<VPII> VVPII;

const double PI = acos(-1.0);
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int MOD = (int) 1e9 + 7;

//------------------------------------------------------------------------

int n;
VI c, sub, P;
VVI g;
VI sol;

int dfs1(int u, int p) {
    sub[u] = (c[u] == -1) ? 1 : 0;
    P[u] = p;
    REP(i, SZ(g[u])) {
        int v = g[u][i];
        if (v != p) {
            sub[u] += dfs1(v, u);
        }
    }
    return sub[u];
}

int dfs(int u, int p) {
    int ret = 0;
    if (u != 0) {
        ret = c[u];
        if (c[u] == -1) {
            c[u] = 1;
        } else {
            c[u] = -1;
        }
        sol.PB(u + 1);
    }
    if (sub[u] + ret == 0) {
        sub[u] += ret;
        return ret;
    }
    REP(i, SZ(g[u])) {
        int v = g[u][i];
        if (v != p && sub[v] != 0) {
            ret += dfs(v, u);
            if (sub[u] + ret == 0) {
                sub[u] += ret;
                return ret;
            }
            ret += c[u];
            if (c[u] == -1) {
                c[u] = 1;
            } else {
                c[u] = -1;
            }
            sol.PB(u + 1);
        }
    }
    sub[u] += ret;
    return ret;
}

int main() {
    SI(n);
    c.resize(n);
    sub.resize(n, 0);
    g.resize(n);
    P.resize(n);
    REP(i, n) {
        SI(c[i]);
    }
    REP(i, n - 1) {
        int a, b;
        SI(a), SI(b);
        a--, b--;
        g[a].PB(b);
        g[b].PB(a);
    }
    dfs1(0, -1);
    sol.PB(1);
    while (sub[0] != 0) {
        dfs(0, -1);
    }
    REP(i, SZ(sol)) {
        printf("%d ", sol[i]);
    }
    printf("\n");
    return 0;
}


#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <set>
#include <utility>
#include <string>
#include <locale>
#include <algorithm>
#include <math.h>
#include <iterator>

#define M_PI           3.1415926535897932384626433832795  /* pi */
#define INT_MAX        2147483647

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef queue<pi> qp;
typedef vector<pi> vp;
typedef vector<string> vs;
typedef map<int, int> mi;

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

	multiset<int> l;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		l.insert(a);
	}

	int m;
	cin >> m;

	vi ml(n);
	vi ms(n);
	for (int i = 0; i < m; i++)
		cin >> ml[i];

	for (int i = 0; i < m; i++)
		cin >> ms[i];

	int maxres = 0;
	int am = 0;
	for (int i = 0; i < m; i++)
	{
		int res = l.count(ml[i]);
		if (res > maxres) {
			maxres = res;
			am = 1;
		}
		else if (res == maxres)
			am++;
	}

	int maxsub = 0;
	if (am != 1)
		for (int i = 0; i < m; i++)
		{
			if (l.count(ml[i]) == maxres) {
				int res = l.count(ms[i]);
				maxsub = max(res, maxsub);
			}
		}

	for (int i = 0; i < m; i++)
	{
		if (l.count(ml[i]) == maxres)
		{
			if (am == 1 || l.count(ms[i]) == maxsub)
			{
				cout << i+1 << endl;
				break;
			}
		}
	}

	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <vector>
#include<cctype>
#include<algorithm>
#include<set>
#include<stack>
#include<map>
#include<time.h>
#include<iterator>
#include <deque>
#include <sstream>
#include<queue>
#include<stdlib.h>
#include<bitset>
#include <utility>

#define fn(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define f1n(i,n) for(int (i) = 1;(i) <= (n);(i)++)
#define mk(f,s) make_pair((f),(s))

#define defV(dp,e) memset(dp,e,sizeof dp)

#define ri(n) scanf("%d",&n)
#define rl(n) scanf("%lld",&n)
#define rs(s) scanf("%s",s)

#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef pair<int ,int > pp;

typedef vector<int  > v1;
typedef vector<ll  > vl;
typedef vector<pp  > vpp;
typedef vector<bool  > vb;
typedef vector<char > vc;
typedef vector<v1 > v2;

typedef map<int ,int > mf;
typedef map<int ,vpp > mv;
typedef map<int ,v1 > ad;

int const siz = 1e9,bound = 7e5,mod = siz+9;
ll const oo=1e18;

map<int ,int > lang;
int aud[bound],n;

int main() {
//	freopen("o.txt","w",stdout);
//	freopen("in.txt","r",stdin);
//	ios::sync_with_stdio(0);cin.tie();
	ri(n);
	fn(i,n){
		int a;
		ri(a);
		lang[a]++;
	}
	int m;
	ri(m);
	fn(i,m)ri(aud[i]);
	int mx=0,pl=0,idx;
	fn(i,m){
		int sub;
		ri(sub);
		if(lang[aud[i]]>mx||lang[aud[i]]==mx&&lang[sub]>pl){
			mx=lang[aud[i]];
			idx=i+1;
			pl=lang[sub];
		}
	}
	printf("%d\n",idx);
	return 0;
}