#include <bits/stdc++.h>
const int maxn = 2e5 + 100;
std::vector<int> v[maxn];
int d[maxn];
int color[maxn];
const int sz = 1e7 + 10;
int stack[sz];
int st = 0;
void push(int x) { stack[st++] = x; }
void push(std::vector<int> x) {
  for (auto y : x) stack[st++] = y;
}
void dfs(int x, int p = -1) {
  int cnt = 0;
  for (int y : v[x]) {
    if (y == p) continue;
    if (d[y] == 1 && color[y] == -1) {
      push({x, y});
      cnt++;
    } else if (d[y] > 1) {
      push(x);
      cnt++;
      dfs(y, x);
      if (color[y] == -1) {
        cnt++;
        push({x, y});
      }
    }
  }
  push(x);
  cnt++;
  if (cnt & 1) color[x] *= -1;
  if (x == 1 && color[x] == -1) {
    push({v[x][0], x, v[x][0]});
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  std::cin >> n;
  for (int i = 1; i <= n; i++) {
    std::cin >> color[i];
  }
  int x, y;
  for (int i = 0; i < n - 1; i++) {
    std::cin >> x >> y;
    d[x]++;
    d[y]++;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  color[1] *= -1;
  dfs(1);
  for (int i = 0; i < st; i++) std::cout << stack[i] << " \n"[i == st - 1];
  return 0;
}
