#include <bits/stdc++.h>
using namespace std;
int n, MP[400005 + 2];
vector<int> G[400005 + 2];
void Dfs(int u, int p) {
  for (int i = 0; i < (int)(G[u].size()); i++) {
    int v = G[u][i];
    if (v == p) continue;
    printf(" %d", v);
    MP[v] ^= 1;
    Dfs(v, u);
    MP[u] ^= 1;
    printf(" %d", u);
    if (MP[v] == 1) {
      MP[v] ^= 1;
      MP[u] ^= 1;
      printf(" %d %d", v, u);
    }
  }
}
int main() {
  int i, j, k, x, y;
  scanf("%d", &n);
  int Onn = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    MP[i] = (x == -1);
    Onn += (x == 1);
  }
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  if (Onn == n) {
    printf("1\n");
    return 0;
  }
  printf("1");
  Dfs(1, -1);
  if (MP[1]) {
    printf(" %d %d %d", G[1][0], 1, G[1][0]);
  }
  printf("\n");
  return 0;
}
