#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
int c[200135], hz[200135];
vector<int> mp[200135];
void dfs(int x, int pa) {
  if (c[x] == -1) hz[x] = 1;
  for (int c : mp[x])
    if (c != pa) {
      dfs(c, x);
      hz[x] += hz[c];
    }
}
void dfs2(int x, int pa) {
  printf("%d ", x);
  if (hz[x] == 0) return;
  for (int v : mp[x])
    if (v != pa) {
      if (hz[v]) {
        c[v] *= -1;
        dfs2(v, x);
        printf("%d ", x);
        c[x] *= -1;
      }
      if (c[v] == -1) {
        printf("%d ", v);
        c[v] *= -1;
        printf("%d ", x);
        c[x] *= -1;
      }
    }
  if (x == 1 && c[x] == -1) {
    int v = mp[1][0];
    printf("%d %d %d\n", v, x, v);
  }
}
void fmain() {
  scanf("%d", &n);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%d", c + i);
  for (int i = 0, u, v; i < n - 1; i++) {
    scanf("%d%d", &u, &v);
    mp[u].push_back(v);
    mp[v].push_back(u);
  };
  dfs(1, 0);
  dfs2(1, 0);
}
int main() {
  fmain();
  return 0;
}
