#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = numeric_limits<double>::epsilon();
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const int MOD = (int)1e9 + 7;
int n;
vector<int> c, sub;
vector<vector<int> > g;
vector<int> sol;
void dfs1(int u, int p) {
  sub[u] = 0;
  sub[u] = !c[u];
  for (int i = 0; i < (int)g[u].size(); i += 1) {
    int v = g[u][i];
    if (v != p) {
      dfs1(v, u);
      sub[u] += sub[v];
    }
  }
}
void dfs(int u, int p) {
  sol.push_back(u + 1);
  c[u] = !c[u];
  while (1) {
    sub[u] = 0;
    for (int i = 0; i < (int)g[u].size(); i += 1) {
      int v = g[u][i];
      if (v != p && sub[v]) {
        dfs(v, u);
        sub[u] += sub[v];
        c[u] = !c[u];
        sol.push_back(u + 1);
      }
    }
    if (!sub[u]) {
      break;
    }
  }
  sub[u] = !c[u];
}
int main() {
  scanf("%d", &n);
  c.resize(n);
  sub.resize(n, 0);
  g.resize(n);
  for (int i = 0; i < n; i += 1) {
    scanf("%d", &c[i]);
    if (c[i] == -1) {
      c[i] = 0;
    }
  }
  for (int i = 0; i < n - 1; i += 1) {
    int a, b;
    scanf("%d", &a), scanf("%d", &b);
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs1(0, -1);
  c[0] = !c[0];
  dfs(0, -1);
  if (!c[0]) {
    sol.push_back(g[0][0] + 1);
    sol.push_back(1);
    sol.push_back(g[0][0] + 1);
  }
  for (int i = 0; i < (int)sol.size(); i += 1) {
    printf("%d ", sol[i]);
  }
  printf("\n");
  return 0;
}
