#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, tot, u, v;
int c[N], head[N], last[N * 2], ver[N * 2];
void add(int x, int y) {
  ver[++tot] = y;
  last[tot] = head[x];
  head[x] = tot;
}
void dfs(int x, int fa) {
  cout << x << " ";
  for (int i = head[x]; i; i = last[i]) {
    int y = ver[i];
    if (y == fa) continue;
    c[y] *= -1;
    dfs(y, x);
  }
  if (c[x] == -1 && x != 1) {
    cout << fa << " " << x << " ";
    c[fa] *= -1;
    c[x] *= -1;
  }
  if (x != 1) {
    if (fa == 1) {
      for (int i = 1; i <= n; i++) {
        if (c[i] == -1) {
          cout << fa << " ";
          c[fa] *= -1;
          return;
        }
      }
    } else {
      cout << fa << " ";
      c[fa] *= -1;
    }
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    add(u, v);
    add(v, u);
  }
  dfs(1, -1);
  return 0;
}
