#include <bits/stdc++.h>
using namespace std;
const int maxn = 200200;
int n;
int color[maxn];
vector<int> G[maxn];
void dfs(int u, int p) {
  for (int i = 0; i < (G[u].size()); i++) {
    int v = G[u][i];
    if (v == p) continue;
    color[v] = -color[v];
    printf("%d ", v);
    dfs(v, u);
    color[u] = -color[u];
    printf("%d ", u);
    if (color[v] == -1) {
      color[v] = -color[v];
      printf("%d ", v);
      color[u] = -color[u];
      printf("%d ", u);
    }
  }
}
int main() {
  int u, v;
  while (~scanf("%d", &n)) {
    memset((color), 0, sizeof(color));
    for (int i = (1); i < (n + 1); i++) {
      scanf("%d", &color[i]);
      G[i].clear();
    }
    for (int i = 0; i < (n - 1); i++) {
      scanf("%d", &u);
      scanf("%d", &v);
      G[u].push_back(v);
      G[v].push_back(u);
    }
    printf("1 ");
    dfs(1, 0);
    if (color[1] == -1) {
      int v = G[1][0];
      color[v] = -color[v];
      printf("%d ", v);
      color[1] = -color[1];
      printf("%d ", 1);
      color[v] = -color[v];
      printf("%d ", v);
    }
  }
  return 0;
}
