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