#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int n, a[maxn];
int E, lnk[maxn], nxt[maxn * 2], son[maxn * 2];
inline void Add(int x, int y) {
  son[++E] = y;
  nxt[E] = lnk[x];
  lnk[x] = E;
}
void Dfs(int x, int fa = 0) {
  for (int j = lnk[x]; j; j = nxt[j])
    if (son[j] != fa)
      printf(" %d", son[j]), a[son[j]] ^= 1, Dfs(son[j], x), printf(" %d", x),
          a[x] ^= 1;
  if (x == 1) {
    if (!a[x]) a[x] ^= 1, printf(" %d %d %d", son[lnk[x]], x, son[lnk[x]]);
  } else if (!a[x])
    a[x] ^= 1, a[fa] ^= 1, printf(" %d %d", fa, x);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == -1) a[i] = 0;
  }
  for (int i = 1, x, y; i < n; i++) scanf("%d%d", &x, &y), Add(x, y), Add(y, x);
  printf("1");
  for (int i = 1; i <= n; i++)
    if (!a[i]) {
      Dfs(1);
      break;
    }
}
