#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  char ch;
  bool ok;
  for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar())
    if (ch == '-') ok = 1;
  for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  if (ok) x = -x;
}
const int maxn = 2e5 + 10, mod = 998244353;
int n, col[maxn], ans[maxn * 50], tot, sz[maxn];
int cnt, pre[maxn * 2], nxt[maxn * 2], h[maxn];
void dfs(int x, int fa) {
  ans[++tot] = x;
  col[x] ^= 1;
  int son = 0;
  for (register int i = h[x]; i; i = nxt[i])
    if (pre[i] != fa) {
      son = pre[i];
      if (!sz[pre[i]]) continue;
      if (sz[pre[i]] == 1 && col[pre[i]]) {
        col[pre[i]] ^= 1, col[x] ^= 1;
        ans[++tot] = pre[i], ans[++tot] = x;
        continue;
      }
      dfs(pre[i], x), ans[++tot] = x;
      col[x] ^= 1;
    }
  if (col[x] && fa) ans[++tot] = fa, ans[++tot] = x, col[x] ^= 1, col[fa] ^= 1;
  if (!col[x] & !fa) ans[++tot] = son, ans[++tot] = x, ans[++tot] = son;
}
void prepare(int x, int fa) {
  sz[x] = col[x];
  for (register int i = h[x]; i; i = nxt[i])
    if (pre[i] != fa) prepare(pre[i], x), sz[x] += sz[pre[i]];
}
void add(int x, int y) {
  pre[++cnt] = y, nxt[cnt] = h[x], h[x] = cnt;
  pre[++cnt] = x, nxt[cnt] = h[y], h[y] = cnt;
}
int main() {
  read(n);
  for (register int i = 1; i <= n; i++)
    read(col[i]), col[i] = (col[i] == -1 ? 1 : 0);
  for (register int i = 1, x, y; i < n; i++) read(x), read(y), add(x, y);
  prepare(1, 0), dfs(1, 0);
  for (register int i = 1; i <= tot; i++) printf("%d ", ans[i]);
}
