#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int val[MAXN], n, u, v;
vector<int> G[MAXN];
vector<int> ansl;
void dfs(int now, int fa) {
  val[now] ^= 1;
  ansl.push_back(now);
  for (auto &i : G[now]) {
    if (i != fa) {
      dfs(i, now);
    }
  }
  if (!val[now] && fa) {
    ansl.push_back(fa);
    ansl.push_back(now);
    val[fa] ^= 1;
    val[now] ^= 1;
  }
  if (fa) {
    val[fa] ^= 1;
    ansl.push_back(fa);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &val[i]);
    if (val[i] == -1) val[i] = 0;
  }
  val[1] ^= 1;
  for (int i = 1; i < n; ++i) {
    scanf("%d %d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, 0);
  if (val[1] == 0) {
    ansl.push_back(G[1][0]);
    ansl.push_back(1);
    ansl.push_back(G[1][0]);
  }
  for (int i = 0; i < ansl.size(); ++i) {
    printf("%d%c", ansl[i], i == ansl.size() - 1 ? '\n' : ' ');
  }
  return 0;
}
