#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int v[maxn];
int pnt[maxn], nxt[maxn], head[maxn];
int t = 1;
void print(int x) {
  printf("%d ", x);
  v[x] *= -1;
}
void dfs(int u, int p) {
  int i = head[u];
  print(u);
  int vv;
  for (int i = head[u]; i; i = nxt[i]) {
    vv = pnt[i];
    if (vv != p) {
      dfs(vv, u);
      print(u);
      if (v[vv] < 0) {
        print(vv);
        print(u);
      }
    }
  }
  if (u == 1 && v[u] > 0) {
    print(vv = pnt[head[u]]);
    print(u);
    print(vv);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &v[i]);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    pnt[t] = v;
    nxt[t] = head[u];
    head[u] = t++;
    pnt[t] = u;
    nxt[t] = head[v];
    head[v] = t++;
  }
  dfs(1, 0);
}
