#include <bits/stdc++.h>
using namespace std;
int n, color[200002];
vector<vector<int> > adjL(200002);
bool first = true, vis[200002];
void dfs(int i) {
  if (!first) color[i] = color[i] == 1 ? -1 : 1;
  first = false;
  printf("%d ", i);
  vis[i] = true;
  for (int j = (0); j <= (int)(((int)(adjL[i]).size()) - 1); j++) {
    int ch = adjL[i][j];
    if (!vis[ch]) {
      dfs(ch);
      printf("%d ", i);
      color[i] = color[i] == 1 ? -1 : 1;
      if (color[ch] == -1) {
        printf("%d %d ", ch, i);
        color[i] = color[i] == 1 ? -1 : 1;
      }
    }
  }
  if (i == 1 and color[1] == -1) {
    printf("%d %d %d", adjL[i][0], i, adjL[i][0]);
  }
}
int main() {
  cin >> n;
  int cntBlack = 0;
  for (int i = (1); i <= (int)(n); i++)
    scanf("%d", &color[i]), cntBlack += color[i] == 1;
  if (cntBlack == n) {
    cout << 1;
    return 0;
  }
  for (int i = (1); i <= (int)(n - 1); i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    adjL[x].push_back(y);
    adjL[y].push_back(x);
  }
  dfs(1);
}
