#include <bits/stdc++.h>
using namespace std;
int n;
int color[200200];
vector<int> g[200200];
void dfs(int p, int u) {
  printf("%d ", u);
  if (color[u] == 1)
    color[u] = -1;
  else
    color[u] = 1;
  for (auto v : g[u])
    if (v != p) {
      dfs(u, v);
      printf("%d ", u);
      if (color[u] == 1)
        color[u] = -1;
      else
        color[u] = 1;
      if (color[v] == -1) {
        printf("%d %d ", v, u);
        color[v] = 1;
        if (color[u] == 1)
          color[u] = -1;
        else
          color[u] = 1;
      }
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &color[i]);
  for (int i = 1, a, b; i < n; ++i) {
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  if (color[1] == 1)
    color[1] = -1;
  else
    color[1] = 1;
  dfs(0, 1);
  if (color[1] == -1) printf("%d 1 %d", g[1][0], g[1][0]);
}
