#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793238;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= 1000000007;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
  }
  return res;
}
vector<int> vec[200005];
int color[200005];
void change(int v) {
  if (color[v] == 1) {
    color[v] = -1;
  } else {
    color[v] = 1;
  }
}
void dfs(int node, int par) {
  int sz = vec[node].size(), u;
  for (int i = 0; i < sz; i++) {
    u = vec[node][i];
    if (u == par) continue;
    printf("%d ", u);
    change(u);
    dfs(u, node);
    change(node);
    printf("%d ", node);
    if (color[u] == -1) {
      printf("%d ", u);
      printf("%d ", node);
      change(u);
      change(node);
    }
  }
  if (node == 1 && color[node] == -1) {
    u = vec[node][0];
    printf("%d ", u);
    printf("%d ", node);
    printf("%d ", u);
  }
}
int main() {
  int n, u, v;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &color[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &u);
    scanf("%d", &v);
    vec[u].push_back(v);
    vec[v].push_back(u);
  }
  printf("1 ");
  dfs(1, -1);
  return 0;
}
