#include <bits/stdc++.h>
using namespace std;
int col[300045];
vector<int> adj[300045];
vector<int> ans;
void dfs(int v, int p) {
  col[v] ^= 1;
  ans.emplace_back(v);
  for (auto u : adj[v]) {
    if (u != p) {
      dfs(u, v);
      ans.emplace_back(v);
      col[v] ^= 1;
    }
  }
  if (col[v] == 0) {
    if (p == -1)
      ans.pop_back();
    else {
      ans.emplace_back(p);
      col[p] ^= 1;
      col[v] ^= 1;
      ans.emplace_back(v);
    }
  }
}
int main() {
  int n, i, tt, x, y;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> tt;
    if (tt == 1)
      col[i] = 1;
    else
      col[i] = 0;
  }
  for (i = 0; i < n - 1; i++) {
    cin >> x >> y;
    adj[x].emplace_back(y);
    adj[y].emplace_back(x);
  }
  col[1] ^= 1;
  dfs(1, -1);
  for (i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  cout << endl;
}
