#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, cnt, head[N], pre[N << 1], to[N << 1], ai[N];
int tot, fi[N << 3];
inline void addedge(int u, int v) {
  pre[++cnt] = head[u];
  head[u] = cnt;
  to[cnt] = v;
}
inline void Mov(int x) { fi[++tot] = x, ai[x] = -ai[x]; }
void sol(int now, int fa) {
  for (int i = head[now]; i; i = pre[i]) {
    int nex = to[i];
    if (nex == fa) continue;
    Mov(nex);
    sol(nex, now);
    Mov(now);
    if (ai[nex] == -1) Mov(nex), Mov(now);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &ai[i]);
  for (int i = 2, x, y; i <= n; i++) {
    scanf("%d%d", &x, &y);
    addedge(x, y);
    addedge(y, x);
  }
  fi[++tot] = 1;
  sol(1, -1);
  if (ai[1] == -1) {
    Mov(to[head[1]]);
    Mov(1);
    Mov(to[head[1]]);
  }
  for (int i = 1; i <= tot; i++) printf("%d ", fi[i]);
  printf("\n");
  return 0;
}
