#include <bits/stdc++.h>
using namespace std;
int n;
class node {
 public:
  int color;
  int pinks;
  vector<int> child;
};
int deepW(int ind, node *v, bool *seen) {
  seen[ind] = true;
  v[ind].pinks = 0;
  if (v[ind].child.size() == 0) return v[ind].color == 1 ? 0 : 1;
  for (vector<int>::iterator i = v[ind].child.begin(); i != v[ind].child.end();
       ++i) {
    if (!seen[*i]) v[ind].pinks += deepW(*i, v, seen);
  }
  return v[ind].pinks + (v[ind].color == 1 ? 0 : 1);
}
bool check(node *v) {
  for (int i = 1; i <= n; ++i) {
    if (v[i].color == -1) return false;
  }
  return true;
}
bool deep(int ind, int father, node *v) {
  v[ind].color *= -1;
  v[ind].pinks = 0;
  cout << ind << " ";
  for (vector<int>::iterator i = v[ind].child.begin(); i != v[ind].child.end();
       ++i) {
    if ((*i) != father) {
      if (v[*i].pinks > 0) {
        if (deep(*i, ind, v)) return true;
        v[ind].color *= -1;
        cout << ind << " ";
      }
    }
  }
  for (vector<int>::iterator i = v[ind].child.begin(); i != v[ind].child.end();
       ++i) {
    if ((*i != father) && (v[*i].color == -1)) {
      if (deep(*i, ind, v)) return true;
      v[ind].color *= -1;
      cout << ind << " ";
    }
  }
  return check(v);
}
int main() {
  cin >> n;
  node v[n + 1];
  bool seen[n + 1];
  for (int i = 1; i <= n; ++i) {
    cin >> v[i].color;
    seen[i] = false;
  }
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    v[y].child.push_back(x);
    v[x].child.push_back(y);
  }
  if (deepW(1, v, seen) == 0) {
    if (v[1].color != -1) {
      cout << "1";
      return 0;
    }
  }
  if (v[1].color == -1) {
    cout << "1 " << v[1].child.at(0) << " ";
    v[1].color = 1;
    v[v[1].child.at(0)].color *= -1;
  }
  if (!check(v)) {
    v[1].color *= -1;
    deep(1, 0, v);
  }
  return 0;
}
