#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
const long long NMAX = 2000 * 1000 + 11;
vector<long long> G[NMAX];
long long color[NMAX];
void put(long long x) {
  color[x] = -color[x];
  cout << " " << x;
}
void dfs(long long u, long long pre) {
  for (long long i = 0; i < G[u].size(); i++) {
    long long v = G[u][i];
    if (v == pre) continue;
    put(v);
    dfs(v, u);
    put(u);
    if (color[v] == -1) {
      put(v);
      put(u);
    }
  }
  if (u == 1 && color[u] == -1) {
    long long v = G[u][0];
    put(v);
    put(u);
    put(v);
  }
}
int32_t main() {
  long long n;
  long long u, v;
  while (scanf("%lld", &n) != -1) {
    for (long long i = 1; i <= n; i++) {
      cin >> color[i];
    }
    for (long long i = 1; i < n; i++) {
      cin >> u >> v;
      G[u].push_back(v);
      G[v].push_back(u);
    }
    cout << "1";
    dfs(1, 1);
    cout << "";
  }
  return 0;
}
