#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 2;
int n, col[MAXN], cnt[MAXN];
vector<int> g[MAXN], res;
bool Dfs(int u, int p) {
  cnt[u] = 1;
  res.push_back(u);
  for (int v : g[u])
    if (v != p) {
      if (Dfs(v, u)) {
        ++cnt[u];
        res.push_back(u);
        if (!(col[v] ^ (cnt[v] & 1))) {
          res.push_back(v);
          res.push_back(u);
          ++cnt[u];
        }
      }
    }
  if (cnt[u] == 1 && col[u]) {
    res.pop_back();
    cnt[u] = 0;
    return false;
  }
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &col[i]), col[i] = (col[i] == 1);
  for (int i = 1, x, y; i < n; ++i) {
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  if (!Dfs(1, 0))
    printf("1");
  else {
    --cnt[1];
    if (!(col[1] ^ (cnt[1] & 1))) {
      res.push_back(g[1][0]);
      res.push_back(1);
      res.push_back(g[1][0]);
    }
    for (int i : res) printf("%d ", i);
  }
  return 0;
}
