#include <bits/stdc++.h>
using namespace std;
vector<int> colors;
vector<vector<int> > g;
vector<int> path;
vector<int> subtree_sum;
int subtree_dfs(int v, int p) {
  subtree_sum[v] = (colors[v] == -1);
  for (int to : g[v]) {
    if (to != p) {
      subtree_sum[v] += subtree_dfs(to, v);
    }
  }
  return subtree_sum[v];
}
bool dfs(int v, int p) {
  path.push_back(v);
  colors[v] *= -1;
  for (int to : g[v]) {
    if (to != p) {
      if (subtree_sum[to] > 0) {
        bool revisit = dfs(to, v);
        path.push_back(v);
        colors[v] *= -1;
        subtree_sum[to] = 0;
        if (revisit) {
          dfs(to, v);
          path.push_back(v);
          colors[v] *= -1;
        }
      }
    }
  }
  if (colors[v] == -1) {
    return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  scanf("%d", &n);
  g.resize(n);
  colors.resize(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &colors[i]);
  }
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  subtree_sum.resize(n);
  subtree_dfs(0, -1);
  colors[0] *= -1;
  if (dfs(0, -1)) {
    int to = g[0][0];
    path.push_back(to);
    path.push_back(0);
    path.push_back(to);
    colors[0] *= -1;
  }
  for (int i = 0; i < path.size(); ++i) {
    printf("%d", path[i] + 1);
    if (i != path.size() - 1) {
      printf(" ");
    }
  }
  printf("\n");
  return 0;
}
