#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int head[N + 10], ver[N * 2 + 10], nxt[N * 2 + 10], tot = 0;
void add(int x, int y) {
  ver[++tot] = y;
  nxt[tot] = head[x];
  head[x] = tot;
}
vector<int> ans;
int p[N + 10];
void change(int x, int fa) {
  p[x] = -p[x];
  p[fa] = -p[fa];
  ans.push_back(x);
  ans.push_back(fa);
}
void dfs(int x, int fa) {
  for (int i = head[x]; i; i = nxt[i]) {
    int y = ver[i];
    if (y == fa) continue;
    ans.push_back(y);
    p[y] = -p[y];
    dfs(y, x);
    ans.push_back(x);
    p[x] = -p[x];
    if (p[y] == -1) change(y, x);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    add(x, y);
    add(y, x);
  }
  dfs(1, -1);
  printf("1 ");
  for (int i = 0; (unsigned)i < ans.size(); i++) printf("%d ", ans[i]);
  if (p[1] == -1) printf("%d 1 %d", ver[head[1]], ver[head[1]]);
  return 0;
}
