#include <bits/stdc++.h>
using namespace std;
int n, co[210000];
vector<int> nn[210000];
int x, y;
void change(int x) {
  co[x] = -co[x];
  printf(" %d", x);
}
void dfs(int now, int fr) {
  for (int i = 0; i < nn[now].size(); i++) {
    int to = nn[now][i];
    if (to == fr) continue;
    change(to);
    dfs(to, now);
    change(now);
    if (co[to] == -1) {
      change(to);
      change(now);
    }
  }
  if (now == 1 && co[now] == -1) {
    change(nn[now][0]);
    change(now);
    change(nn[now][0]);
  }
}
int main() {
  while (scanf("%d", &n) == 1) {
    for (int i = 1; i <= n; i++) scanf("%d", &co[i]);
    for (int i = 1; i <= n; i++) nn[i].clear();
    for (int i = 1; i <= n - 1; i++) {
      scanf("%d %d", &x, &y);
      nn[x].push_back(y);
      nn[y].push_back(x);
    }
    printf("1");
    dfs(1, 1);
  }
}
