#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int head[N], tot, nxt[N], ver[N];
int color[N];
int fa[N];
int n;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
void add(int x, int y) {
  tot++;
  ver[tot] = y;
  nxt[tot] = head[x];
  head[x] = tot;
}
void Get_Fa(int x, int fat) {
  fa[x] = fat;
  for (int i = head[x]; i; i = nxt[i])
    if (ver[i] != fat) Get_Fa(ver[i], x);
}
void Solve(int x) {
  printf("%d ", x);
  for (int i = head[x]; i; i = nxt[i]) {
    int y = ver[i];
    if (y == fa[x]) continue;
    color[y] ^= 1;
    Solve(y);
    printf("%d ", x);
    color[x] ^= 1;
    if (!color[y]) {
      printf("%d %d ", y, x);
      color[y] = 1;
      color[x] ^= 1;
    }
  }
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    int x = read();
    if (x == -1) x = 0;
    color[i] = x;
  }
  for (int i = 1; i < n; i++) {
    int u = read(), v = read();
    add(u, v);
    add(v, u);
  }
  Get_Fa(1, 0);
  Solve(1);
  if (!color[1]) {
    for (int i = head[1]; i; i = nxt[i]) {
      printf("%d %d %d", ver[i], 1, ver[i]);
      break;
    }
  }
  return 0;
}
