#include <bits/stdc++.h>
using namespace std;
const int maxn = 200050;
int n, c[maxn];
vector<int> e[maxn];
inline void Go(int v) {
  printf(" %d", v);
  c[v] = -c[v];
}
void dfs(int u, int fa) {
  int len = e[u].size();
  for (int i = 0; i < len; ++i)
    if (e[u][i] != fa) {
      Go(e[u][i]);
      dfs(e[u][i], u);
      Go(u);
    }
  if (c[u] == -1 && u != 1) Go(fa), Go(u);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", c + i);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  cout << "1", dfs(1, 0);
  if (c[1] == -1) Go(e[1][0]), Go(1), Go(e[1][0]);
}
