#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, k;
int c[N], parent[N];
int order[N], q[N];
vector<int> g[N];
vector<int> answ;
void build(int v) {
  order[v] += 1;
  q[v] += c[v];
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == parent[v]) continue;
    parent[to] = v;
    build(to);
    order[v] += order[to];
    q[v] += q[to];
  }
}
void update(int v) {
  c[v] = (c[v] == 1) ? -1 : 1;
  k += c[v];
}
void dfs(int v) {
  if (k == n) return;
  if (v != 1) update(v);
  answ.push_back(v);
  if (k == n) return;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == parent[v]) continue;
    if (order[to] == q[to]) continue;
    dfs(to);
    if (k == n) return;
    answ.push_back(v);
    update(v);
    if (k == n) return;
    if (c[to] == -1) {
      update(to);
      answ.push_back(to);
      if (k == n) return;
      update(v);
      answ.push_back(v);
      if (k == n) return;
    }
  }
}
int main() {
  scanf("%d", &n);
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
    if (c[i] == 1) k++;
  }
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  if (n != 1 && k == n - 1 && c[1] == -1) {
    cout << 1 << " " << g[1][0] << " " << 1 << " " << g[1][0] << endl;
    return 0;
  }
  build(1);
  bool flag = true;
  for (int i = 1; i <= n; i++) {
    if (q[i] != order[i]) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << 1 << endl;
    return 0;
  }
  dfs(1);
  for (int i = 0; i < answ.size(); i++) {
    printf("%d ", answ[i]);
  }
  cout << endl;
  return 0;
}
