#include <bits/stdc++.h>
using namespace std;
struct node {
  int id;
  vector<node*> neigh;
  node* parent;
  int color;
  int n;
};
node T[200010];
int n, a, b, done;
void visit(node* n) {
  cout << n->id << " ";
  while (n->n < n->neigh.size()) {
    auto c = n->neigh[n->n];
    if (c == n->parent) {
      n->n++;
      continue;
    }
    if (c->color == 1 && c->n == c->neigh.size()) {
      n->n++;
      continue;
    }
    c->parent = n;
    c->color *= -1;
    visit(c);
    return;
  }
  if (n->parent->id != 0) {
    n->parent->color *= -1;
    visit(n->parent);
    return;
  } else {
    if (n->color == 1) return;
    int x = n->neigh[0]->id;
    cout << x << " 1 " << x << endl;
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  T[0].id = 0;
  for (int i = 1; i <= n; i++) {
    cin >> T[i].color;
    T[i].id = i;
  }
  T[1].parent = &T[0];
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    T[a].neigh.push_back(&T[b]);
    T[b].neigh.push_back(&T[a]);
  }
  visit(&T[1]);
}
