#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
using ll = long long;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;
int n;
int a[maxn];
vector<int> g[maxn];
vector<int> ans;
void dfs(int at, int p = -1) {
  ans.push_back(at);
  for (int to : g[at]) {
    if (to != p) {
      a[to] = -a[to];
      dfs(to, at);
      ans.push_back(at);
      a[at] = -a[at];
    }
  }
  if (a[at] == -1) {
    if (at == 0) {
      ans.pop_back();
      a[at] = -a[at];
    } else {
      ans.push_back(p);
      a[p] = -a[p];
      ans.push_back(at);
      a[at] = -a[at];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(0);
  for (int i = 0; i < n; i++) {
    assert(a[i] == 1);
  }
  for (int x : ans) cout << x + 1 << " ";
  cout << endl;
  return 0;
}
