#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int vis[200005], c[200005], fa[200005];
vector<int> g[200005];
vector<int> ans;
int flag;
void init(int u) {
  vis[u] = 1;
  for (int v : g[u]) {
    if (vis[v]) continue;
    fa[v] = u;
    init(v);
  }
}
void f(int u) {
  ans.push_back(u);
  c[u] = -c[u];
  if (g[u].size() == 1 && u != 1) return;
  for (int v : g[u]) {
    if (fa[u] == v) continue;
    f(v);
    if (c[v] == -1) {
      ans.push_back(u);
      ans.push_back(v);
      ans.push_back(u);
      c[v] = 1;
    } else {
      ans.push_back(u);
      c[u] = -c[u];
    }
  }
}
void work(int u) {
  ans.push_back(u);
  for (int v : g[u]) {
    f(v);
    if (c[v] == -1) {
      ans.push_back(u);
      ans.push_back(v);
      ans.push_back(u);
      c[v] = 1;
    } else {
      ans.push_back(u);
      c[u] = -c[u];
    }
  }
  if (c[u] == -1) flag = 1;
}
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> c[i];
  for (int i = 1; i <= n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  init(1);
  work(1);
  if (flag) {
    ans.push_back(g[1][0]);
    ans.push_back(1);
    ans.push_back(g[1][0]);
    c[1] = -c[1];
  }
  for (int i : ans) cout << i << " ";
}
