#include <bits/stdc++.h>
using namespace std;
vector<int> e[200100];
int ans[200100];
int a[200100];
int cnt;
int dfs(int x, int fa) {
  ans[cnt++] = x;
  int flag = 0;
  for (int i = 0; i < e[x].size(); i++) {
    int to = e[x][i];
    if (to == fa) continue;
    if (dfs(to, x)) {
      ans[cnt++] = x;
      a[x] ^= 1;
      flag = 1;
    }
  }
  if (x == 1 && !flag && a[x]) {
    int to = e[x][0];
    printf("%d %d %d %d", x, to, x, to);
  } else if ((x != 1 && a[x]) || (x == 1 && !a[x])) {
    for (int i = 0; i < cnt; i++) {
      printf("%d ", ans[i]);
    }
    cnt = 0;
    flag = 1;
  } else if (flag) {
    a[fa] ^= 1;
    ans[cnt++] = fa;
    ans[cnt++] = x;
  } else
    cnt--;
  return flag;
}
int main() {
  int n, x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    a[i] = 1 - (a[i] == 1);
  }
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dfs(1, 1);
  printf("\n");
  return 0;
}
