#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;
const int maxn = 200005;
vector<int> g[maxn];
int fat[maxn];
vector<int> son[maxn];
int now[maxn];
bool has[maxn];
int i, j, k, l, m, n;
queue<int> q;
void DFS(int x, int y) {
  fat[x] = y;
  if (now[x] < 0) has[x] = true;
  for (unsigned int i = 0; i < g[x].size(); i++) {
    int v = g[x][i];
    if (fat[v] != 0) continue;
    son[x].push_back(v);
    DFS(v, x);
    if (now[v] < 0 || has[v]) has[x] = true;
  }
}
void find(int x) {
  q.push(x);
  if (x > 1) now[x] = -now[x];
  if (son[x].size() == 0) {
    has[x] = false;
    return;
  }
  for (unsigned int i = 0; i < son[x].size(); i++) {
    int v = son[x][i];
    if (has[v]) {
      find(v);
      now[x] = -now[x];
      q.push(x);
    }
  }
  for (unsigned int i = 0; i < son[x].size(); i++) {
    int v = son[x][i];
    if (has[v]) {
      find(v);
      now[x] = -now[x];
      q.push(x);
    }
  }
  if (now[x] < 0)
    has[x] = true;
  else
    has[x] = false;
  if (x == 1 && has[x]) {
    q.push(son[1][0]);
    q.push(x);
    q.push(son[1][0]);
  }
}
int main() {
  scanf("%d", &n);
  memset(has, 0, sizeof(has));
  for (i = 1; i <= n; i++) scanf("%d", &now[i]);
  for (i = 1; i <= n - 1; i++) {
    scanf("%d%d", &j, &k);
    g[j].push_back(k);
    g[k].push_back(j);
  }
  DFS(1, -1);
  while (!q.empty()) q.pop();
  find(1);
  n = 0;
  while (!q.empty()) {
    m = q.front();
    q.pop();
    if (m == 0) continue;
    n++;
    if (n > 1) printf(" ");
    printf("%d", m);
  }
  return 0;
}
