#include <bits/stdc++.h>
template <class T>
inline void rd(T &x) {
  char c = getchar();
  x = 0;
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
}
template <class T>
void Out(T a) {
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  if (a >= 10) Out(a / 10);
  putchar(a % 10 + '0');
}
using namespace std;
const int N = 210000;
int co[N], tr[N], po[1005000];
vector<int> q[N];
int s;
void Pre(int now, int old) {
  int l, x;
  int tmp = 0;
  if (co[now] == -1)
    tr[now] = 1;
  else
    tr[now] = 0;
  l = q[now].size();
  for (int i = 0; i < l; i++) {
    x = q[now][i];
    if (x == old) continue;
    Pre(x, now);
    tmp += tr[x];
  }
  tr[now] += tmp;
  return;
}
void Go(int now) {
  s++;
  po[s] = now;
  co[now] *= -1;
  if (co[now] == 1)
    tr[now]--;
  else
    tr[now]++;
  return;
}
void Bfs(int now, int old) {
  int l, x;
  Go(now);
  l = q[now].size();
  for (int i = 0; i < l; i++) {
    x = q[now][i];
    if (x == old) continue;
    if (tr[x] == 0) continue;
    Bfs(x, now);
    Go(now);
    if (co[x] == -1) {
      Go(x);
      Go(now);
    }
  }
  return;
}
int main() {
  int n, x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &co[i]);
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    q[x].push_back(y);
    q[y].push_back(x);
  }
  Pre(1, 0);
  s = 0;
  if (co[1] == -1) {
    x = q[1][0];
    Go(1);
    Go(x);
  }
  co[1] *= -1;
  if (co[1] == 1)
    tr[1]--;
  else
    tr[1]++;
  Bfs(1, 0);
  if (co[1] == -1) s--;
  for (int i = 1; i <= s; i++) printf("%d ", po[i]);
  return 0;
}
