#include <bits/stdc++.h>
using namespace std;
const int SIZE = 2 * 1e5 + 1;
vector<int> adj[SIZE];
bool colors[SIZE];
int chld[SIZE];
void cnt_children(int cur, int p) {
  for (int i = 0; i < int(adj[cur].size()); i++) {
    if (adj[cur][i] != p) {
      cnt_children(adj[cur][i], cur);
      chld[cur] += chld[adj[cur][i]];
    }
  }
  chld[cur] += !colors[cur];
}
void dfs(int cur, int p) {
  for (int i = 0; i < adj[cur].size(); i++) {
    int v = adj[cur][i];
    if (chld[v] == 0 || v == p) continue;
    printf("%d ", v + 1);
    colors[v] = (!colors[v]);
    dfs(v, cur);
    colors[cur] = (!colors[cur]);
    printf("%d ", cur + 1);
    if (!colors[v]) {
      printf("%d %d ", v + 1, cur + 1);
      colors[cur] = (!colors[cur]);
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int cur;
    scanf("%d", &cur);
    if (cur == 1) colors[i] = 1;
  }
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  cnt_children(0, -1);
  printf("1 ");
  dfs(0, -1);
  if (!colors[0]) {
    int v = adj[0][0];
    printf("%d 1 %d", v + 1, v + 1);
  }
  return 0;
}
