#include <bits/stdc++.h>
using namespace std;
const int NMAX = 200007;
int n;
int color[NMAX], sl[NMAX];
vector<int> ke[NMAX];
void creat(int bef, int now) {
  sl[now] += (int)(color[now] == -1);
  for (int i = 0; i < ke[now].size(); i++)
    if (ke[now][i] != bef) {
      creat(now, ke[now][i]);
      sl[now] += sl[ke[now][i]];
    }
}
void fix(int bef, int now) {
  printf("%d ", now);
  color[now] *= -1;
  for (int i = 0; i < ke[now].size(); i++)
    if ((ke[now][i] != bef) && (sl[ke[now][i]] > 0)) {
      fix(now, ke[now][i]);
      printf("%d ", now);
      color[now] *= -1;
    }
  if ((now != 1) && (color[now] == -1)) {
    printf("%d ", bef);
    printf("%d ", now);
    color[bef] *= -1;
    color[now] *= -1;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &color[i]);
  for (int i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    ke[u].push_back(v);
    ke[v].push_back(u);
  }
  creat(0, 1);
  if (color[1] == -1) {
    bool ok = true;
    for (int i = 0; i <= ke[1].size() - 1; i++)
      if (sl[ke[1][i]] > 0) {
        ok = false;
        break;
      }
    if (ok) {
      printf("%d %d %d %d", 1, ke[1][0], 1, ke[1][0]);
      return 0;
    }
  }
  color[1] *= -1;
  fix(0, 1);
  if (color[1] == -1) printf("%d %d %d", ke[1][0], 1, ke[1][0]);
  return 0;
}
