#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5;
int a[maxn], f[maxn];
vector<int> g[maxn];
int ans[maxn];
int n, i, x, y, cnt, la;
void prepare(int o, int fa) {
  f[o] = 1;
  int len = g[o].size(), i;
  for (i = 0; i < len; i++) {
    int v = g[o][i];
    if (v == fa) continue;
    prepare(v, o);
    f[o] &= f[v];
  }
  if (a[o] == -1) f[o] = 0;
}
void dfs(int o, int fa) {
  int len = g[o].size(), i;
  for (i = 0; i < len; i++) {
    int v = g[o][i];
    if (v == fa) continue;
    if (f[v]) continue;
    ans[++la] = v;
    a[v] *= -1;
    cnt += a[o];
    dfs(v, o);
    if (cnt < n) {
      ans[++la] = o;
      a[o] *= -1;
      cnt += a[o];
    }
  }
  if (a[o] < 0 && fa) {
    ans[++la] = fa;
    a[fa] *= -1;
    cnt += a[fa];
    ans[++la] = o;
    a[o] *= -1;
    cnt += a[o];
  }
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > 0) cnt++;
  }
  for (i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  ans[la = 1] = 1;
  prepare(1, 0);
  dfs(1, 0);
  if (a[1] < 0) {
    int v = g[1][0];
    ans[++la] = v;
    a[v] *= -1;
    cnt += a[v];
    ans[++la] = 1;
    a[1] *= -1;
    cnt += a[1];
    ans[++la] = v;
    a[v] *= -1;
    cnt += a[v];
  }
  for (i = 1; i <= la; i++) printf("%d%c", ans[i], i < la ? ' ' : '\n');
  return 0;
}
