#include <bits/stdc++.h>
using namespace std;
const long long maxn = 200005;
typedef struct node {
  vector<int> next;
  int color;
} Node;
Node bear[maxn];
int vis[maxn];
int val[maxn];
int sum;
void flip(int id) { bear[id].color = -bear[id].color; }
bool del(int id) {
  if (bear[id].color == -1) return false;
  int cnt = 0;
  for (int i = 0; i < bear[id].next.size(); i++) {
    if (!vis[bear[id].next[i]]) {
      cnt++;
    }
    if (cnt > 1) {
      return false;
    }
  }
  sum--;
  return true;
}
int findmin(int id) {
  int minv = maxn, x = -1;
  for (int i = 0; i < bear[id].next.size(); i++) {
    if (!vis[bear[id].next[i]]) {
      if (sum != 1 || bear[bear[id].next[i]].color == -1) {
        if (bear[bear[id].next[i]].color == -1) return bear[id].next[i];
        if (val[bear[id].next[i]] < minv) {
          minv = val[bear[id].next[i]];
          x = bear[id].next[i];
        }
      }
    }
  }
  return x;
}
void dfs(int id) {
  val[id]++;
  printf("%d ", id);
  flip(id);
  vis[id] = del(id);
  int x = findmin(id);
  if (x != -1) {
    dfs(x);
  }
}
int main(int argc, const char* argv[]) {
  memset(vis, 0, sizeof(vis));
  memset(val, 0, sizeof(val));
  int n;
  bool allb = true;
  scanf("%d", &n);
  sum = n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &bear[i].color);
    if (bear[i].color == -1) allb = false;
  }
  if (allb) {
    printf("1");
    return 0;
  }
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    bear[a].next.push_back(b);
    bear[b].next.push_back(a);
  }
  flip(1);
  dfs(1);
  return 0;
}
