#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int M = 1e6 + 5;
const int inf = 1000000000;
const int md = 1e4 + 7;
const long double eps = 0.000000001;
int n, i, x, y, c[N], d[N];
vector<int> q[N];
void dfs(int v, int p = -1) {
  d[v] = 1 - c[v];
  for (int i = 0; i < q[v].size(); ++i)
    if (q[v][i] != p) {
      dfs(q[v][i], v);
      d[v] += d[q[v][i]];
    }
}
void goChange(int v, int p = -1) {
  cout << v << " ";
  for (int i = 0; i < q[v].size(); ++i) {
    int to = q[v][i];
    if (to == p) continue;
    if (d[to]) {
      d[v] -= d[to];
      if (c[to])
        ++d[to];
      else
        --d[to];
      c[to] = 1 - c[to];
      goChange(to, v);
      cout << v << " ";
      c[v] = 1 - c[v];
    }
  }
  if (c[v] == 0) {
    if (p != -1) {
      cout << p << " ";
      c[p] = 1 - c[p];
      cout << v << " ";
      c[v] = 1 - c[v];
    } else {
      cout << q[v][0] << " ";
      cout << v << " ";
      cout << q[v][0] << " ";
    }
  }
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (i = 1; i <= n; ++i) {
    cin >> c[i];
    if (c[i] == -1) c[i] = 0;
  }
  for (i = 1; i < n; ++i) {
    cin >> x >> y;
    q[x].push_back(y);
    q[y].push_back(x);
  }
  dfs(1);
  goChange(1);
}
