#include <bits/stdc++.h>
using namespace std;
int n, tot, sum1, cnt, h[200005], c[200005];
struct Edge {
  int next, to;
} a[400000];
void Addedge(int x, int y) {
  a[++cnt].to = y;
  a[cnt].next = h[x];
  h[x] = cnt;
}
void Go(int x) {
  c[x] = -c[x];
  printf("%d ", x);
}
void DFS(int x, int fa) {
  for (int i = h[x]; i; i = a[i].next) {
    int y = a[i].to;
    if (y == fa) continue;
    Go(y);
    DFS(y, x);
    Go(x);
    if (c[y] == -1) {
      Go(y);
      Go(x);
    }
  }
  if (x == 1 && c[x] == -1) {
    int y = a[h[1]].to;
    Go(y);
    Go(x);
    Go(y);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
  }
  for (int i = 1, x, y; i < n; i++) {
    scanf("%d%d", &x, &y);
    Addedge(x, y);
    Addedge(y, x);
  }
  printf("1 ");
  DFS(1, 0);
  return 0;
}
