#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const int msz = 212345;
struct Edge {
  int v, next;
};
Edge eg[msz << 1];
bool ned[msz];
int val[msz];
int head[msz];
int tp;
void Add(int u, int v) {
  eg[tp].v = v;
  eg[tp].next = head[u];
  head[u] = tp++;
}
bool dfs1(int u, int pre) {
  int v;
  ned[u] = !val[u];
  for (int i = head[u]; i != -1; i = eg[i].next) {
    v = eg[i].v;
    if (v == pre) continue;
    if (dfs1(v, u)) ned[u] = 1;
  }
  return ned[u];
}
bool f;
void prt(int u) {
  if (f)
    putchar(' ');
  else
    f = 1;
  printf("%d", u);
}
void dfs2(int u, int pre) {
  prt(u);
  for (int i = head[u]; i != -1; i = eg[i].next) {
    int v = eg[i].v;
    if (v == pre || !ned[v]) continue;
    val[v] ^= 1;
    dfs2(v, u);
    prt(u);
    val[u] ^= 1;
    if (!val[v]) {
      prt(v);
      prt(u);
      val[v] ^= 1;
      val[u] ^= 1;
    }
  }
  if (u == pre && !val[u]) {
    int v = eg[head[u]].v;
    prt(v);
    prt(u);
    prt(v);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &val[i]);
    if (val[i] == -1) val[i] = 0;
  }
  memset(head, -1, sizeof(head));
  tp = 0;
  int u, v;
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &u, &v);
    Add(u, v);
    Add(v, u);
  }
  dfs1(1, 1);
  f = 0;
  dfs2(1, 1);
  return 0;
}
