#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)2e5 + 5;
const long long INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;
vector<int> G[maxn];
int type[maxn];
void dfs(int u, int fa) {
  int len = G[u].size();
  for (__typeof(len - 1) i = 0; i <= (len - 1); i++) {
    int v = G[u][i];
    if (v == fa) continue;
    type[v] = -type[v], printf("%d ", v);
    dfs(v, u);
    type[u] = -type[u], printf("%d ", u);
    if (type[v] == -1) {
      type[v] = -type[v], printf("%d ", v);
      type[u] = -type[u], printf("%d ", u);
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (__typeof(n) i = 1; i <= (n); i++) scanf("%d", type + i);
  for (__typeof(n - 1) i = 1; i <= (n - 1); i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  printf("1 ");
  dfs(1, -1);
  if (type[1] == -1) {
    int v = G[1][0];
    printf("%d %d %d ", v, 1, v);
  }
  puts("");
  return 0;
}
