#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
vector<int> d[maxn];
int a[maxn];
void dfs(int x, int fa) {
  printf("%d ", x);
  if (x != 1) a[x] ^= 1;
  for (int i = 0; i < d[x].size(); i++) {
    int son = d[x][i];
    if (son == fa) continue;
    dfs(son, x);
    printf("%d ", x);
    a[x] ^= 1;
  }
  if (!a[x]) {
    if (x != 1) {
      printf("%d %d ", fa, x);
      a[fa] ^= 1;
    } else {
      printf("%d %d %d ", d[x][0], x, d[x][0]);
    }
  }
}
int main() {
  int n, x, y;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == -1) a[i] = 0;
  }
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    d[x].push_back(y);
    d[y].push_back(x);
  }
  dfs(1, 0);
  return 0;
}
