#include <bits/stdc++.h>
using namespace std;
vector<int> adjancylist[200010];
int color[200010];
int visited[200010];
void dfs(int n) {
  visited[n] = 1;
  printf("%d ", n + 1);
  color[n] = (color[n] + 1) % 2;
  int size = adjancylist[n].size();
  for (int i = 0; i < size; ++i) {
    int current = adjancylist[n][i];
    if (visited[current] == 0) {
      dfs(current);
      printf("%d ", n + 1);
      color[n] = (color[n] + 1) % 2;
      if (color[current] == 0) {
        printf("%d %d ", current + 1, n + 1);
        color[n] = (color[n] + 1) % 2;
      }
      color[current] = (color[current] + 1) % 2;
    }
  }
}
int main() {
  int n, temp, point1, point2;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    visited[i] = 0;
    scanf("%d", &temp);
    if (temp == -1)
      color[i] = 0;
    else
      color[i] = 1;
  }
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d %d", &point1, &point2);
    point1--;
    point2--;
    adjancylist[point1].push_back(point2);
    adjancylist[point2].push_back(point1);
  }
  color[0] = (color[0] + 1) % 2;
  dfs(0);
  if (color[0] == 0)
    printf("%d 1 %d", adjancylist[0][0] + 1, adjancylist[0][0] + 1);
  printf("\n");
}
