#include <bits/stdc++.h>
int n, col[200001], head[200001], cnte;
struct edge {
  int to, nxt;
} edges[200001 << 1];
void add(int u, int v) {
  edges[++cnte].to = v;
  edges[cnte].nxt = head[u];
  head[u] = cnte;
}
void dfs(int u, int fa) {
  for (int i = head[u]; i; i = edges[i].nxt) {
    int v = edges[i].to;
    if (v == fa) {
      continue;
    }
    col[v] = -col[v];
    printf("%d ", v);
    dfs(v, u);
    col[u] = -col[u];
    printf("%d ", u);
    if (col[v] == -1) {
      col[v] = -col[v];
      printf("%d ", v);
      col[u] = -col[u];
      printf("%d ", u);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &col[i]);
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  printf("1 ");
  dfs(1, 0);
  if (col[1] == -1) {
    int v = edges[head[1]].to;
    printf("%d %d %d", v, 1, v);
  }
  return 0;
}
