#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 10;
int c[MAXN], cou = 0, n;
bool vis[MAXN], hasp[MAXN];
vector<int> g[MAXN];
void innode(int s) {
  printf("%d ", s);
  c[s] = -c[s];
  if (c[s] == 1)
    cou++;
  else
    cou--;
}
bool dfs1(int s) {
  vis[s] = true;
  if (c[s] == -1) hasp[s] = true;
  for (int i = 0; i < g[s].size(); i++) {
    if (!vis[g[s][i]]) hasp[s] = dfs1(g[s][i]) || hasp[s];
  }
  return hasp[s];
}
void dfs2(int s) {
  vis[s] = true;
  if (cou == n) return;
  for (int i = 0; i < g[s].size() && cou != n; i++) {
    if (!vis[g[s][i]]) {
      if (cou == n) break;
      innode(g[s][i]);
      dfs2(g[s][i]);
      if (cou == n) break;
      innode(s);
      if (c[g[s][i]] == -1) {
        innode(g[s][i]);
        if (cou == n) break;
        innode(s);
        if (cou == n) break;
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c[i]);
    if (c[i] == 1) cou++;
  }
  int from, to;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d %d", &from, &to);
    g[from].push_back(to);
    g[to].push_back(from);
  }
  if (cou != n) {
    printf("1 ");
    dfs1(1);
    memset(vis, false, sizeof(vis));
    dfs2(1);
  } else
    printf("1\n");
  return 0;
}
