#include <bits/stdc++.h>
using namespace std;
vector<int> edge[200005];
int vis[200005];
void dfs(int son, int parent) {
  printf("%d ", son);
  for (int i = 0; i < edge[son].size(); i++) {
    int nex = edge[son][i];
    if (nex != parent) {
      vis[nex] *= -1;
      dfs(nex, son);
      vis[son] *= -1;
      printf("%d ", son);
    }
  }
  if (-1 == vis[son]) {
    if (parent == 0) {
      int nex = edge[son][0];
      vis[son] *= -1;
      printf("%d %d %d", nex, son, nex);
    } else {
      vis[parent] *= -1;
      vis[son] *= -1;
      printf("%d ", parent);
      printf("%d ", son);
    }
  }
}
int main() {
  int n, v1, v2;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &vis[i]);
  }
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &v1, &v2);
    edge[v1].push_back(v2);
    edge[v2].push_back(v1);
  }
  dfs(1, 0);
  return 0;
}
