#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, mod = 10007;
int color[maxn];
vector<int> ans, g[maxn];
void dfs(int fa, int u) {
  color[u] *= -1;
  ans.push_back(u);
  for (auto v : g[u])
    if (v != fa) {
      dfs(u, v);
      color[u] *= -1;
      ans.push_back(u);
    }
  if (color[u] == -1) {
    if (fa == -1) {
      color[u] *= -1;
      ans.pop_back();
      return;
    }
    color[fa] *= -1;
    ans.push_back(fa);
    color[u] *= -1;
    ans.push_back(u);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &color[i]);
  color[1] *= -1;
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(-1, 1);
  for (int i = 0; i < ans.size(); i++)
    printf("%d%c", ans[i], i == ans.size() - 1 ? '\n' : ' ');
  return 0;
}
